Seeing for ourselves the effect of malloc(3) allocations on the heap and process virtual address space is interesting and educational. Check out the output of the following code example (the source is available in this book's Git repository):
$ ./malloc_brk_test -h
Usage: ./malloc_brk_test [option | --help]
option = 0 : show only mem pointers [default]
option = 1 : opt 0 + show malloc stats as well
option = 2 : opt 1 + perform larger alloc's (over MMAP_THRESHOLD)
option = 3 : test segfault 1
option = 4 : test segfault 2
-h | --help : show this help screen
$
There are several scenarios running in this application; let's examine some of them now.