3 ms·
An important part of glibc malloc design is that it expects developers to free memory in a reverse order of allocation, otherwise a lot of memory will be ‘locke
by nerdponx 6y ago
An important part of glibc malloc design is that it expects developers to free memory in a reverse order of allocation, otherwise a lot of memory will be ‘locked’, and never returned to the system.
I'm a C novice and generally inexperienced with languages that require memory management. Nobody ever tells you this stuff!
Is this a very specific GNU concern, or do I have to keep this in mind in general on other systems when using their default allocators?
- flip89 6y agoI think, this particular part of the design is here for historical reasons. The classic way of allocating memory in Unix systems was heap extension with brk/sbrk calls, so glibc malloc from beginning was designed using these syscalls and logic. So with this mechanism you need to free last allocated object to shrink the heap. Now, allocators often get new memory from system using mmap syscall and probably have different expectations.