|
Message-ID: <20190707192200.GA2684@voyager> Date: Sun, 7 Jul 2019 21:22:00 +0200 From: Markus Wichmann <nullplan@....net> To: musl@...ts.openwall.com Subject: Re: malloc() alignment and max_align_t On Sun, Jul 07, 2019 at 07:17:48PM +0100, Chris Hall wrote: > Clearly, C11 does not require malloc() to align exactly as max_align_t, and > bigger is fine. > > But I'm curious as to why SIZE_ALIGN is twice as big as it needs to be ? > Design decision. For the algorithm to work, every chunk needs to be able to contain four machine words (one struct chunk). And with a bit of maneuvering, this alignment can just be achieved on all chunks with minimal waste (if a completely new region is allocated in expand_heap(), then two machine words at the start of it are wasted, but if the new memory happens to be directly behind the previous section, no waste occurs at all). This makes it easier to reason about chunk sizes. Right now, SIZE_ALIGN and minimum chunk size (after adding OVERHEAD) are the same. If we lowered the alignment to two machine words, that would change. > Thanks, > > Chris Ciao, Markus
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.