2 ms·
Does malloc() use brk() or mmap()? https://stackoverflow.com/questions/30542428/does-malloc-use-brk-or-mmap https://stackoverflow.com/questions/30542428/does-m
by jjoonathan 7y ago
Does malloc() use brk() or mmap()?
https://stackoverflow.com/questions/30542428/does-malloc-use-brk-or-mmap https://stackoverflow.com/questions/30542428/does-malloc-use...
there is a mallopt named M_MMAP_THRESHOLD, in general:
If requested memory is less than it, brk() will be used;
If requested memory is larger than or equals to it, mmap() will be used;
- masklinn 7y agoThis is linux-specific though. Non-glibc mallocs have different tuning and many have completely foresworn brk/sbrk (openbsd and dragonflybsd mallocs haven't used brk in more than a decade[0]). In fact brk/sbrk is deprecated in every BSD: On OpenBSD, DragonflyBSD, NetBSD and OSX: > The brk and sbrk functions are historical curiosities left over from earlier days before the advent of virtual memory management. On FreeBSD: > The brk() and sbrk() functions are legacy interfaces from before the advent of modern virtual memory management. They are deprecated and not present on the arm64 or riscv architectures. It's also somewhat discouraged on Solaris: > The behavior of brk() and sbrk() is unspecified if an application also uses any other memory functions (such as malloc(3C), mmap(2), free(3C)). [0] https://bugs.dragonflybsd.org/issues/84 https://bugs.dragonflybsd.org/issues/84