what is the suggested number of bytes each time for files too large to be memory mapped at one time?

StackOverflow https://stackoverflow.com/questions/1031073

  •  06-07-2019
  •  | 
  •  

Question

I am opening files using memory map. The files are apparently too big (6GB on a 32-bit PC) to be mapped in one ago. So I am thinking of mapping part of it each time and adjusting the offsets in the next mapping.

Is there an optimal number of bytes for each mapping or is there a way to determine such a figure?

Thanks.

Was it helpful?

Solution

There is no optimal size. With a 32-bit process, there is only 4 GB of address space total, and usually only 2 GB is available for user mode processes. This 2 GB is then fragmented by code and data from the exe and DLL's, heap allocations, thread stacks, and so on. Given this, you will probably not find more than 1 GB of contigous space to map a file into memory.

The optimal number depends on your app, but I would be concerned mapping more than 512 MB into a 32-bit process. Even with limiting yourself to 512 MB, you might run into some issues depending on your application. Alternatively, if you can go 64-bit there should be no issues mapping multiple gigabytes of a file into memory - you address space is so large this shouldn't cause any issues.

You could use an API like VirtualQuery to find the largest contigous space - but then your actually forcing out of memory errors to occur as you are removing large amounts of address space.

EDIT: I just realized my answer is Windows specific, but you didn't which platform you are discussing. I presume other platforms have similar limiting factors for memory-mapped files.

OTHER TIPS

Does the file need to be memory mapped?

I've edited 8gb video files on a 733Mhz PIII (not pleasant, but doable).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top