3 ms·
Malloc will not unmap memory. Period. That would have huge performance cost in multi-thread programs.
by ncmncm 4y ago
Malloc will not unmap memory. Period. That would have huge performance cost in multi-thread programs.
- klodolph 4y agoThis is factually false, and I'm wondering why you'd say that. Some of the more common malloc implementations out there are dlmalloc, jemalloc, and tcmalloc. Here is where they call munmap. https://github.com/ennorehling/dlmalloc/blob/71296436f979a350870e10b869ccfd28bfcc17e4/malloc.c#L3859 https://github.com/ennorehling/dlmalloc/blob/71296436f979a35... https://github.com/jemalloc/jemalloc/blob/c0c9783ec9289e6d1de749ff20081af65bdd78b8/src/pages.c#L233 https://github.com/jemalloc/jemalloc/blob/c0c9783ec9289e6d1d... Note that not all allocators work this way, you can see that tcmalloc will instead MADV_DONTNEED. (You can find munmap in tcmalloc, but it's not being used to free memory.) https://github.com/google/tcmalloc/blob/48808681a9f38e974b49619a126f6f949ff59520/tcmalloc/system-alloc.cc#L411 https://github.com/google/tcmalloc/blob/48808681a9f38e974b49...
- ncmncm 4y agoI am corrected. Now I need to start turning on nonstandard flags to disable it.