Re: MemPools rewrite

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Wed, 18 Oct 2000 23:45:22 +0200

Andres Kroonmaa wrote:

> this alignment is one of the major sources of memory waste. This is
> a must for general purpose allocator I guess, but inside squid?

Well.. for x86 plaforms the alignment requirement is 4 bytes, but malloc
aligns everything on 8 bytes to make sure the smallest fragment is large
enought to at least contain the malloc metadata..

On other platforms other alignments are required. A good rule of thumb
is that structures must be aligned to the word size of the processor
(almost exclusively 32 or 64 bits today, but might change in the future)

Compilers know about the alignment requirements when performing pointer
arithmetics, so to find the aligned size of a type you can do

  (int)((((type *)NULL)+1)-(type *)NULL)

I bet there also is GCC compiler builtin directives for this if you want
to play it the fancy way and risk being bitten by compability problems
with other compilers...

--
Henrik Nordstrom
Squid hacker
Received on Wed Oct 18 2000 - 15:47:28 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:12:51 MST