Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Increase number of files that can be opened

Increase number of files that can be opened

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Amit4u
    wrote on last edited by
    #1

    in windows, how do i set maximum open number of files ? i tried to set FOPEN_MAX in stdio.h file, but it's not working.... need help.... thanks in advance...

    xyz

    V C I L 4 Replies Last reply
    0
    • A Amit4u

      in windows, how do i set maximum open number of files ? i tried to set FOPEN_MAX in stdio.h file, but it's not working.... need help.... thanks in advance...

      xyz

      V Offline
      V Offline
      vineeshV
      wrote on last edited by
      #2

      override the definition of FOPEN_MAX in your code not in stdio.h as #deinfe FOPEN_MAX //n is the value you need to set .

      vineesh

      C 1 Reply Last reply
      0
      • A Amit4u

        in windows, how do i set maximum open number of files ? i tried to set FOPEN_MAX in stdio.h file, but it's not working.... need help.... thanks in advance...

        xyz

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        Why do you think you can set it?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        1 Reply Last reply
        0
        • V vineeshV

          override the definition of FOPEN_MAX in your code not in stdio.h as #deinfe FOPEN_MAX //n is the value you need to set .

          vineesh

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          Do you really think such a #define will be of any help? :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
          [My articles]

          V 1 Reply Last reply
          0
          • A Amit4u

            in windows, how do i set maximum open number of files ? i tried to set FOPEN_MAX in stdio.h file, but it's not working.... need help.... thanks in advance...

            xyz

            I Offline
            I Offline
            Iain Clarke Warrior Programmer
            wrote on last edited by
            #5

            The limit will be in the actual library code - the constant in the header is just to let you know about the limit. You may be able to recompile your own version of the libraries with a higher max value, but there may be other factors causing the limitation. Or you could use API functions like CreateFile instead. The limit for that is "May as well be infinite. If you need to know the actual limit, you're in bigger trouble than you think". Iain.

            Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.

            1 Reply Last reply
            0
            • C CPallini

              Do you really think such a #define will be of any help? :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              V Offline
              V Offline
              vineeshV
              wrote on last edited by
              #6

              The actual definition of FOPEN_MAX in stdio.h is #define FOPEN_MAX 20 you can extend it to some limit (around 500) The below code works fine #include <stdio.h> #include <windows.h> #define FOPEN_MAX 500 FILE *stream, *stream2; int main( void ) { int numclosed; int fd =3; while (fd <= FOPEN_MAX) { if( (stream = fopen( "E:\\new.txt", "r" )) == NULL ) { printf( "The file was not opened\n [%d] ",GetLastError()); getchar(); } else { fd = fileno(stream); printf( "The file was opened and fd is [%d] \n " ,fd); } } numclosed = _fcloseall( ); printf( "Number of files closed by _fcloseall: %u\n", numclosed ); return 0; } ============

              vineesh

              C 1 Reply Last reply
              0
              • V vineeshV

                The actual definition of FOPEN_MAX in stdio.h is #define FOPEN_MAX 20 you can extend it to some limit (around 500) The below code works fine #include <stdio.h> #include <windows.h> #define FOPEN_MAX 500 FILE *stream, *stream2; int main( void ) { int numclosed; int fd =3; while (fd <= FOPEN_MAX) { if( (stream = fopen( "E:\\new.txt", "r" )) == NULL ) { printf( "The file was not opened\n [%d] ",GetLastError()); getchar(); } else { fd = fileno(stream); printf( "The file was opened and fd is [%d] \n " ,fd); } } numclosed = _fcloseall( ); printf( "Number of files closed by _fcloseall: %u\n", numclosed ); return 0; } ============

                vineesh

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #7

                I don't get the point of doing that. Please see here [^] (as Iain explained very well the real purpose of FOPEN_MAX). :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

                V 1 Reply Last reply
                0
                • C CPallini

                  I don't get the point of doing that. Please see here [^] (as Iain explained very well the real purpose of FOPEN_MAX). :)

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  V Offline
                  V Offline
                  vineeshV
                  wrote on last edited by
                  #8

                  Yes Iain was correct ... The actual libary code restrict the number of file open to 510 (i dont know the exact value ..).But normally the system will not allow you to open more than 20 files from a process .This is because of the FOPEN_MAX set to 20 in the header stdio.h . #define FOPEN_MAX 20 We can only change the value below 510 . #define FOPEN_MAX 510 //upto this will work that means #define FOPEN_MAX 511 may not work as it trying to override the max limit in the actual libray code We cannot open infinite number of files using fopen ,but still we can extend the limit set in the stdio.h file as above . The usage of CreateFile is an absolute replacement for fopen if you need to open file more than 500 times from a single process.

                  vineesh

                  1 Reply Last reply
                  0
                  • A Amit4u

                    in windows, how do i set maximum open number of files ? i tried to set FOPEN_MAX in stdio.h file, but it's not working.... need help.... thanks in advance...

                    xyz

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    http://msdn.microsoft.com/en-us/library/6e3b887c(VS.80).aspx[^] http://msdn.microsoft.com/en-us/library/xt874334(VS.80).aspx[^] http://www.codeproject.com/script/Forums/View.aspx?fid=1644&msg=2504818[^] Best Wishes, -David Delaune

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups