In other words, why doesn't free()
just return the memory to the operating system, and malloc
simply request memory from the operating system?
This unpacks to three closely related questions:
C
need to manage its own heap? (Is it because the OS will only allow you to allocate and free contiguous memory of a minimum size?)malloc
is a C method itself. You are using a standard library that provides it for you, but in the end, it is C code just like yours is.mmap
). This is too big for your regular data structure.