0

I have a program that is creating a map file, its able to do that call just fine, m_hMap = CreateFileMapping(m_hFile,0,dwProtect,0,m_dwMapSize,NULL);, but when the subsequent function call to MapViewOfFile(m_hMap,dwViewAccess,0,0,0), I get an error code of 8, which is ERROR_NOT_ENOUGH_MEMORY, or error string "error Not enough storage is available to process this command".

So I'm not totally understanding what the MapViewOfFile does for me, and how to fix the situation.

some numbers...

m_dwMapSize = 453427200
dwProtect = PAGE_READWRITE;
dwViewAccess = FILE_MAP_ALL_ACCESS;

I think my page size is 65536

nagates
  • 620
  • 13
  • 40
  • How large is the file you are trying to map? – Tomdarkness Mar 22 '13 at 15:14
  • I assume you are intending to map only the first ~432MB of the file, right? Anyway, does your process have enough virtual memory available to map the file? The limit is, by default, 2GB on 32bit windows. – Tomdarkness Mar 22 '13 at 15:23
  • Well, so It seems like is creating and destroying memory views, and growing as needed, It wouldn't totally surprise me if its trying to eventually load the whole thing into memory. – nagates Mar 22 '13 at 16:20

2 Answers2

1

In case of very large file and to read it, it is recommended to read it in small pieces and then process each piece. And MapViewOfFile function is used to map a piece in memory.

Look at http://msdn.microsoft.com/en-us/library/windows/desktop/aa366761(v=vs.85).aspx need offset to do its job properly i.e. in case you want to read a very large file in pieces. Mostly due to fragmentation and related reason very large memory request fails.

Saqlain
  • 17,490
  • 4
  • 27
  • 33
  • so what is m_hMap = CreateFileMapping(m_hFile,0,dwProtect,0,m_dwMapSize,NULL); doing? Isn't allocating the memory? – nagates Mar 22 '13 at 15:54
  • 1
    You can imagine MapViewOfFile as a malloc+memcpy of the file you are opening, nothing more (under the hood it is the reverse: malloc can use a slab'ed memory mapping). So MapViewOfFile normally just chooses an address where it can fit the file view's bytes continuously in memory. – Saqlain Mar 23 '13 at 16:13
0

If you are working on a 64 bit processor then the system will allocate a total of 4GB memory with bit set LargeaddressAware. go to Configuration properties->linker->system. in Enable largeaddressware: check Yes /LARGEADDRESSAWARE and check.