- 论坛徽章:
- 0
|
我想知道在Linux、HP-Unix、Aix、Solaris等平台下,常见编译器实现的fopen能够同时打开的文件数上限。在相应的平台上,是否有系统设置或者编译器提供的函数可以被用来调整这个上限值。
比如,Windows下VC9实现的fopen默认能够最大打开512个文件,但可以通过_setmaxstdio函数设置其上限达到2048。对于其它平台及其上的编译器,由于没有相关平台可供测试,也没有相关的经验,故请教大家。
下面有一段测试代码:
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- using namespace std;
- int main()
- {
- int count = 0;
-
- for (;;)
- {
- char buf[256];
- sprintf(buf, "logs\\log_%d.txt", ++count);
- FILE *pFile = fopen(buf, "a+");
- if (pFile == NULL)
- {
- cout << "Failed to create the file \"" << buf << "\"\n";
- cout << "Error msg: " << strerror(errno) << endl;
- break;
- }
- else
- {
- fprintf(pFile, "a line for test\n");
- cout << "Created a file, No." << count << endl;
- }
- }
- }
复制代码 |
|