【问题标题】:_setmaxstdio max open files is 2048 only?_setmaxstdio 最大打开文件数仅为 2048?
【发布时间】:2009-11-26 13:02:54
【问题描述】:

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

有没有办法让每个应用程序使用 _wopen 一次打开超过 2048 个文件。

32 或 64 位操作系统 - 相同的限制!

【问题讨论】:

    标签: c windows


    【解决方案1】:

    没有。 通过查看 CRT 源代码,我们可以知道 CRT 限制了最大数量。

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

    NHANDLE

    #define _NHANDLE_           (IOINFO_ARRAYS * IOINFO_ARRAY_ELTS)
    

    那些常量:

    /*
     * 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
    

    如您所见,它受到 CRT 实施的限制。

    【讨论】:

      【解决方案2】:

      没有。

      我相信限制与从 CreateProcess 调用继承打开文件的能力有关。 CreateProcess 只有 2048 个用于传递句柄的槽(在 32 位和 64 位上)。您可以调试程序并进入系统、执行或生成 CRT 函数以查看 2048 个插槽的限制。

      如果您使用 Win32 文件 API(CreateFile、WriteFile、ReadFile、CloseHandle 等),那么您对打开的文件没有限制(嗯,您有,但我相信它基于您的资源,例如内存)。

      【讨论】:

        【解决方案3】:

        Is there a limit on number of open files in Windows

        从接受答案的 cmets 看来,没有办法改变这一点。或许您可以使用“CreateFile”api 调用来代替 _wopen?

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-03-07
          • 2011-10-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多