malloc vs mmap in C

前端 未结 6 846
广开言路
广开言路 2020-12-22 23:36

I built two programs, one using malloc and other one using mmap. The execution time using mmap is much less than using malloc

6条回答
  •  独厮守ぢ
    2020-12-23 00:34

    mmap doesn't actually read the file. It just maps it to address space. That's why it's so fast, there is no disc I/O until you actually access that region of address space.

    malloc is simply a mapping of address space to memory

提交回复
热议问题