windows下fopen打开文件个数是否有限制

yaohua1210 2010-12-29 09:33:11
char FilePath[256] = {0};
for (int i = 0; i < 1000; i++)
{
FILE* pFile;
sprintf(FilePath, "D:\\1\\%d.txt", i);
if ((pFile = fopen(FilePath, "wb")) == NULL)
{
}
}
window下每次都能打开509个文件。
请教:是进程打开文件数目有限制还是什么原因?
有什么解决方法没?
...全文
822 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zuokui 2013-08-03
  • 打赏
  • 举报
回复
如果不用fclose有没有别的办法可以提高个数?
jx2010yqq 2012-12-10
  • 打赏
  • 举报
回复
根据你的数据我推测windows下应该能打开512个文件,0,1,2被占用,还剩509个。ubuntu系统下能打开1024个。
jx2010yqq 2012-12-10
  • 打赏
  • 举报
回复
貌似是有限制,我在ubuntu系统下测试了一下,最多有1024个文件描述符。每个文件文件指针对应一个文件描述符,因此,打开的文件数应该不能超过1024个。windows系统的情况应该也比较类似。一般情况下,没有必要同时操控这么多文件吧,而且打开文件还比较占资源。可以先打开一部分文件,比如说100个,操作完后,关闭,然后再打开其他文件,如果有必要操作之前关闭的文件,可重复打开。以上是我个人认为的,不一定正确,仅供参考。
fire_woods 2010-12-29
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 q191201771 的回复:]
那我接个分吧
[/Quote]
就想叫yoko 2010-12-29
  • 打赏
  • 举报
回复
那我接个分吧
yaohua1210 2010-12-29
  • 打赏
  • 举报
回复
找到问题!!结贴!!!
yaohua1210 2010-12-29
  • 打赏
  • 举报
回复
The _setmaxstdio function changes the maximum value for the number of files which may be simultaneously open at the stdio level.

C run-time I/O now supports many more open files on Win32 platforms than in previous versions. Up to 2,048 files may 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 may be open simultaneously at the stdio level (that is, opened and accessed by means of the fopen, fgetc, fputc, and so forth family of functions). The limit of 512 open files at the stdio level may be increased to a maximum of 2,048 by means of the _setmaxstdio function.

Since 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.

Note This upper limit may be beyond what is supported by a particular Win32 platform and configuration
rolax 2010-12-29
  • 打赏
  • 举报
回复
貌似C语言对文件的打开和创建是比较少,你可以尝试使用MFC中对文件操作的方法。不过测试的话,会让电脑半天没反应。

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧