Take the 2-minute tour ×

I want to reach parts of a large file randomly. After opening the part I needed with mmap if I need another part of the file. Should I close the first memory mapped region and mmap again or can I open two memory mapped region at the same time?

I don't want to map all the file since it could be larger than the RAM and I will use multiple files open at the same time on my program.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Mmapping does not consume RAM. You can and should map the entire file unless it is larger than the available address space. On a 64-bit computer, that's rather unlikely. On 32-bits, it's not impossible.

In any case, you can make as many mappings as you want of each single file.

share|improve this answer
I want to be able to open 20-30 number of files. On a 32-bits system If I open 2 4GB-files at the same time, will I be out of address space.? –  Berk Feb 11 '12 at 20:36
On a 32-bit system can't map all of even one 4GB file. So make many little mappings of pieces, as per my second paragraph. –  bmargulies Feb 11 '12 at 21:20
add comment

Your Answer


