Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_setmaxstdio max open files is 2048 only?

Tags:

c

windows

http://msdn.microsoft.com/en-us/library/6e3b887c(VS.80).aspx

is there a way to have more than 2048 open files at a time per application using _wopen.

32 or 64 bit OS – same limit!

like image 729
marutis Avatar asked Nov 26 '09 13:11

marutis


People also ask

How many file descriptors can be opened in Windows?

By default, up to 512 files can be open simultaneously at the stream I/O level. This level includes files opened and accessed using the fopen , fgetc , and fputc family of functions. The limit of 512 open files at the stream I/O level can be increased to a maximum of 8,192 by use of the _setmaxstdio function.


3 Answers

No. By looking into the CRT source code, we can know the CRT limited the max number.

 /*
 * Make sure the request is reasonable.
 */
_VALIDATE_RETURN(((maxnum >= _IOB_ENTRIES) && (maxnum <= _NHANDLE_)), EINVAL, -1);

The NHANDLE:

#define _NHANDLE_           (IOINFO_ARRAYS * IOINFO_ARRAY_ELTS)

Those constants:

/*
 * Definition of IOINFO_L2E, the log base 2 of the number of elements in each
 * array of ioinfo structs.
 */
#define IOINFO_L2E          5

/*
 * Definition of IOINFO_ARRAY_ELTS, the number of elements in ioinfo array
 */
#define IOINFO_ARRAY_ELTS   (1 << IOINFO_L2E)

/*
 * Definition of IOINFO_ARRAYS, maximum number of supported ioinfo arrays.
 */
#define IOINFO_ARRAYS       64

As you can see, it's limited by the implementation of the CRT.

like image 58
Misty Avatar answered Oct 04 '22 08:10

Misty


No.

I believe the limit has to do with the ability to inherit the open files from a CreateProcess call. The CreateProcess has only 2048 slots for passing handles (both on 32-bit and 64-bit). You can debug a program and step into the system, exec, or spawn CRT functions to see the limit of the 2048 slots.

If you use the Win32 file API (CreateFile, WriteFile, ReadFile, CloseHandle, etc.), then you don't have a limit on open files (well, you do but I believe it is based on your resources like memory).

like image 35
Stephen L. De Rudder Avatar answered Oct 04 '22 08:10

Stephen L. De Rudder


See Is there a limit on number of open files in Windows.

From the comments on the accepted answer it looks like there is no way to change this. Perhaps you can use the "CreateFile" api call in place of _wopen?

like image 44
Jeff Foster Avatar answered Oct 04 '22 06:10

Jeff Foster