3 ms·
Can you explain what you mean by mmap is how memory is obtained nowadays?
by andi999 6y ago
Can you explain what you mean by mmap is how memory is obtained nowadays?
- yaantc 6y agommap is not only to map a file content into a process address space, it can also be used to request memory from the OS using the MAP_ANONYMOUS flag. Early on a malloc-like allocator would use brk/sbrk to get a chunk of "raw" memory, and manage this for the user providing access using malloc/free. Nowadays the same "raw" memory can be obtained using an anonymous map. A raw pool, when unused, can be returned to the OS by unmapping it. Using an anonymous map provides address space randomization by default (for the raw pool location), whereas brk/sbrk extends a limit and because of this are predictable.
- DmitrySoshnikov 6y agosbrk is emulated via mmap today on MacOS and others, this is an abstraction (for bump allocation), not just a function you may implement custom sbrk via mmap easily
- mhh__ 6y agosbrk isn't even supported on some platforms anymore, if I'm not mistaken