I'm opening lots of files with fopen() in VC++ but after a while it fails.
Is there a limit to the number of files you can open simultaneously?
The C run-time libraries have a 512 limit for the number of files that can be open at any one time.
The open-file limit is a setting that controls the maximum number of open files for individual users (such as non-root users). The default open-file limit is typically 1024.
The "Too many open files" message means that the operating system has reached the maximum "open files" limit and will not allow SecureTransport, or any other running applications to open any more files. The open file limit can be viewed with the ulimit command: The ulimit -aS command displays the current limit.
Maximum number of files on disk: 4,294,967,295. Maximum number of files in a single folder: 4,294,967,295.
The C run-time libraries have a 512 limit for the number of files that can be open at any one time. Attempting to open more than the maximum number of file descriptors or file streams causes program failure. Use _setmaxstdio
to change this number. More information about this can be read here
Also you may have to check if your version of windows supports the upper limit you are trying to set with _setmaxstdio
. For more information on _setmaxstdio
check here
Information on the subject corresponding to VS 2015 can be found here
In case anyone else is unclear as to what the limit applies to, I believe that this is a per-process limit and not system-wide.
I just wrote a small test program to open files until it fails. It gets to 2045 files before failing (2045 + STDIN + STDOUT + STDERROR = 2048), then I left that open and ran another copy.
The second copy showed the same behaviour, meaning I had at least 4096 files open at once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With