(转)windows下fopen遇到文件限制的解决方法

来源:互联网 发布:如何淘宝兼职 编辑:程序博客网 时间:2024/05/16 08:20

转自:http://blog.csdn.net/joyyoj/article/details/5447150


昨天遇到一个问题:打开shp文件到85个时,发现再添加shp就会报错。我一开始怀疑是缓存写的有问题,后来跟踪了下,才发现问题居然在fopen,又测试下一把fopen,如果fopen读取txt,发现在读取第510个文件时就会失败。于是怀疑是文件打开数目有限制,搜索了一把,更改config.NT重启计算机还是不行。最后是使用_setmaxstdio提高了上限。

MSDN里的描述如下:

C run-time I/O now supports many more open files on Win32 platforms than in previous versions. Up to 2,048 files can be open simultaneously at the lowio level (that is, opened and accessed by means of the _open_read_write, and so forth family of I/O functions). Up to 512 files can be open simultaneously at the stdio level (that is, opened and accessed by means of the fopenfgetcfputc, and so forth family of functions). The limit of 512 open files at the stdio level can be increased to a maximum of 2,048 by means of the _setmaxstdio function.

Because stdio-level functions, such as fopen, are built on top of the lowio functions, the maximum of 2,048 is a hard upper limit for the number of simultaneously open files accessed through the C run-time library.

原创粉丝点击