What are the advantages and disadvantages if we always use mmap to allocate memory instead of malloc ?
Siddhesh Poyarekar
siddhesh.poyarekar@gmail.com
Thu Aug 13 08:42:00 GMT 2020
On Thu, 13 Aug 2020 at 06:50, 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
> How large are the blocks of memory?
> Will it causes a waste of memory if the entire program calls malloc to allocate
> totally 1 byte (and no such an invocation is called anymore).
One the larger side***, the allocations will be of the order of 64MB,
but there's a catch. The allocations do not have any physical pages
backing them, so while they allocate address space, they don't
allocate any real memory except for the 1byte (or rather, ~32 bytes
(or rather, the page containing the 32 bytes), counting the alignment
requirements and malloc internal metadata) that the user requests.
Siddhesh
*** The larger side is typically for non-main arenas. The main arena
is allocated using brk() and can be grown a page at a time.
--
http://siddhesh.in
More information about the Libc-help
mailing list