mmap and memory usage

后端 未结 3 549
别那么骄傲
别那么骄傲 2021-02-05 12:37

I am writing a program that receives huge amounts of data (in pieces of different sizes) from the network, processes them and writes them to memory. Since some pieces of data ca

3条回答
  •  梦毁少年i
    2021-02-05 13:13

    The main advantage of mmap with big files is to share the same memory mapping between two or more file: if you mmap with MAP_SHARED, it will be loaded into memory only once for all the processes that will use the data with the memory saving.

    But AFAIK , mmap maps the entire file into memory (Here you can find examples of how mmap fails with files bigger than physical mem + swap space.) so if you access the file from a single process, it will not help you with the physical memory consumption.

提交回复
热议问题