In malloc, why use brk at all? Why not just use mmap?

前端 未结 5 1574
失恋的感觉
失恋的感觉 2021-02-13 10:28

Typical implementations of malloc use brk/sbrk as the primary means of claiming memory from the OS. However, they also use mmap

5条回答
  •  清酒与你
    2021-02-13 10:50

    The system call brk() has the advantage of having only a single data item to track memory use, which happily is also directly related to the total size of the heap.

    This has been in the exact same form since 1975's Unix V6. Mind you, V6 supported a user address space of 65,535 bytes. So there wasn't a lot of thought given for managing much more than 64K, certainly not terabytes.

    Using mmap seems reasonable until I start wondering how altered or added-on garbage collection could use mmap but without rewriting the allocation algorithm too.

    Will that work nicely with realloc(), fork(), etc.?

提交回复
热议问题