Typical implementations of malloc
use brk
/sbrk
as the primary means of claiming memory from the OS. However, they also use mmap
mmap()
didn't exist in the early versions of Unix. brk()
was the only way to increase the size of the data segment of the process at that time. The first version of Unix with mmap()
was SunOS
in the mid 80's, the first open-source version was BSD-Reno in 1990.
And to be usable for malloc()
you don't want to require a real file to back up the memory. In 1988 SunOS implemented /dev/zero
for this purpose, and in the 1990's HP-UX implemented the MAP_ANONYMOUS
flag.
There are now versions of mmap()
that offer a variety of methods to allocate the heap.