Re: MemPools rewrite

From: Henrik Nordstrom <hno@dont-contact.us>
Date: Thu, 19 Oct 2000 08:00:52 +0200

Alex Rousskov wrote:

> "The allocated space is suitably aligned (after
> possible pointer coercion) for storage of any type
> of object. If the space is at least pagesize bytes
> in length (see getpagesize((3)),) the returned
> memory will be page boundary aligned as well."

The page boundary thing is an BSD extension and cannot be relied on for
portable applications. Not covered by standards, or implemented on many
other platforms.

The first part is true by definition in C, for C objects only. Other
types of objects such as hardware dependent I/O buffers may require
alignments outside the scope of C.

> Sizeof() accounts for padding within a single structure. Henrik's trick
> with pointer arithmetic is probably safer for arrays. The two may be
> equivalent, but I am not sure (and would not rely on it).

I have been reading up a little and it seems structures are always
padded to a size suitable for arrays if needed, so using sizeof() should
be safe.

Also the pointer arithmetic thing failed quite miserably from being
overworked... I hereby withdraw that statement ;-) (I can give you a
new one that works, but there is no point in it as sizeof() is
sufficient).

I thougth structures was only internally padded, but padding is also
performed after the last member to get the structure size correct for
alignment in arrays.

/Henrik
Received on Thu Oct 19 2000 - 00:42:47 MDT

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