What this book is describing is an example of how memory allocation can work. It's a very common example, but there are platforms that work differently. It describes a multitasking platform with virtual memory.
There are two aspects to memory allocation on a multitasking platform: first the task receives some memory from the operating system; then the task itself manages its own memory. The paragraph you cited describes the first step.
On this typical platform, when the task asks the operating system for more memory (by making a system call to the kernel, e.g. with the brk
system call on traditional Unix systems), the kernel of the operating system finds some physical memory that isn't used by any other task, marks it in its internal data structures as being in use, and references them in the task's memory map at the end of a consecutive segment of virtual addresses called BSS or heap. Furthermore this memory is zeroed out so that the task won't read some data left over by another task.
The malloc
function works by allocating chunks of the heap area. It works entirely inside the task's heap. It only makes a system call to obtain more memory if the heap is full. On most platforms, the malloc
function does not overwrite the memory that it allocates, for performance. So when a block of memory is used for the first time after it's been obtained from the operating system, it'll happen to be zeroed out. But if the memory has already been used inside the task because it's been obtained with malloc
, then freed with free
, and reused by another malloc
, then the memory will contain whatever the task put there the first time around.