When to use memory-mapped files?

前端 未结 3 1358
日久生厌
日久生厌 2020-12-08 06:48

I have an application that receives chunks of data over the network, and writes these to disk. Once all chunks have been received, they can be decoded/recombined into the si

3条回答
  •  轮回少年
    2020-12-08 07:04

    Memory-mapped files are primarily used for Inter-Process Communication or I/O performance improvement.

    In your case, are you trying to get better I/O performance?

    Hate to point out the obivious, but Wikipedia gives a good rundown of the situation... http://en.wikipedia.org/wiki/Memory-mapped_file

    Specifically...

    The memory mapped approach has its cost in minor page faults - when a block of data is loaded in page cache, but not yet mapped in to the process's virtual memory space. Depending on the circumstances, memory mapped file I/O can actually be substantially slower than standard file I/O.

    It sounds like you're about to prematurely optimize for speed. Why not a regular file approach, and then refactor for MM files later if needed?

提交回复
热议问题