Mmap allocating memory in a heap?

I read about mmap on wikipedia and tried this example http://en.wikipedia.org/wiki/Mmap#Example_of_usage . I compiled this program with gcc and ran the valgrind overit command.

Here is the output of valgrind:

# valgrind a.out ==7018== Memcheck, a memory error detector ==7018== Copyright (C) 2002-2011, and GNU GPL'd, by Julian Seward et al. ==7018== Using Valgrind-3.7.0 and LibVEX; rerun with -h for copyright info ==7018== Command: a.out ==7018== PID 7018: anonymous string 1, zero-backed string 1 PID 7019: anonymous string 1, zero-backed string 1 PID 7018: anonymous string 2, zero-backed string 2 ==7018== ==7018== HEAP SUMMARY: ==7018== in use at exit: 0 bytes in 0 blocks ==7018== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==7018== ==7018== All heap blocks were freed -- no leaks are possible ==7018== ==7018== For counts of detected and suppressed errors, rerun with: -v ==7018== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) PID 7019: anonymous string 2, zero-backed string 2 ==7019== ==7019== HEAP SUMMARY: ==7019== in use at exit: 0 bytes in 0 blocks ==7019== total heap usage: 0 allocs, 0 frees, 0 bytes allocated ==7019== ==7019== All heap blocks were freed -- no leaks are possible ==7019== ==7019== For counts of detected and suppressed errors, rerun with: -v ==7019== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) 

My question

Does mmap provide memory on the heap? if not, what does munmap do?

+6
source share
2 answers

In a Unix-like system, your program address space consists of one or more areas of virtual memory, each of which is displayed by the OS in physical memory, in a file, or nothing at all.

The heap, generally speaking, is one specific area of ​​memory created by the C runtime environment and managed by malloc (which, in turn, uses the brk and sbrk system calls for growth and compression).

mmap is a way to create new memory regions independently of malloc (and therefore independent of the heap). munmap is just its reverse, it frees up these areas.

+13
source

mmapped memory is neither a heap nor a stack. It maps to the virtual address space of the calling process, but is not allocated on the heap.

+4
source

All Articles