Heap
wikipedia Data segment # Program memory # Heap
The heap area commonly begins at the end of the .bss
and .data
segments and grows to larger addresses from there. The heap area is managed by malloc, calloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single "heap area" is not required to fulfill the contract(合同、契约) of malloc/calloc/realloc/free; they may also be implemented using mmap/munmap to reserve/unreserve potentially non-contiguous regions of virtual memory into the process' virtual address space). The heap area is shared by all threads, shared libraries, and dynamically loaded modules in a process.
NOTE: OS重要提供了两种使用heap的方式:
1) malloc, calloc, realloc, and free
2) mmap/munmap