0

I have 1400 files (315GB), trying to optimize random access by mapping all these file, but get ERROR_NOT_ENOUGH_MEMORY on 7000 file(189GB), whats I'm doing wrogn (Windows 10, x64)

auto hFileHadnle = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
auto mapper_handles = CreateFileMapping(
        hFileHadnle,    // use paging file
        NULL,                    // default security
        PAGE_READONLY,          // read access
        0,                       // maximum object size (high-order DWORD)
        filelen,                // maximum object size (low-order DWORD)
        0);                 // name of mapping object

auto data = MapViewOfFile(mapper_handles,   // handle to map object
        FILE_MAP_READ, // read/write permission
        0,
        0,
        0);
CloseHandle(mapper_handles);
CloseHandle(hFileHadnle);
Heorhiy
  • 190
  • 2
  • 14
  • The error is you assume that it can be done. It cannot. There are limits. 7000 open file handles is one of them. – Dialecticus Nov 23 '20 at 14:56
  • I also think so, there is some limit around 8000, try opening smaller files and see if you still get the same error. – Sven Nilsson Nov 23 '20 at 15:00
  • 1
    The solution is to have less than N (N < 7000) files open at the same time. If you need to open another file then first close one. Which one? [It's up to you to decide.](https://en.wikipedia.org/wiki/Cache_replacement_policies) – Dialecticus Nov 23 '20 at 15:01
  • Here is some more info about these limits: https://stackoverflow.com/questions/870173/is-there-a-limit-on-number-of-open-files-in-windows – Sven Nilsson Nov 23 '20 at 15:08
  • 2
    Do you really need so many files open *simultaneously*? What are you doing with the files exactly that you can't do with just a handful open at a time? – Remy Lebeau Nov 23 '20 at 16:14

0 Answers0