Code for malloc and free

The POSIX interface of malloc is defined here. If you want to find out how the C library in GNU/Linux (glibc) implements malloc, go and get the source code from http://ftp.gnu.org/gnu/glibc/ or browse the git repository and look at the malloc/malloc.c file. There is also the base documentation of the Memory Allocator by Doug Lea … Read more

Is free() zeroing out memory?

There’s no single definitive answer to your question. Firstly, the external behavior of a freed block will depend on whether it was released to the system or stored as a free block in the internal memory pool of the process or C runtime library. In modern OSes the memory “returned to the system” will become … Read more

Problem usage memory in C

For good reasons, virtually no memory allocator returns blocks to the OS Memory can only be removed from your program in units of pages, and even that is unlikely to be observed. calloc(3) and malloc(3) do interact with the kernel to get memory, if necessary. But very, very few implementations of free(3) ever return memory … Read more