Re: MemPools rewrite

From: Alex Rousskov <rousskov@dont-contact.us>
Date: Fri, 27 Oct 2000 17:34:03 -0600 (MDT)

On Sat, 28 Oct 2000, Andres Kroonmaa wrote:

> from this I tend to conclude that sizeof() returns sizes suitably aligned
> for use in arrays.

Sure, there is no argument here. The problem is that you cannot stuck
a pointer inside an element of an array of an arbitrary type. That is,

        *(char**)(array+i) = ptr_to_something;

is not safe for some types of arrays on some machines. Just like

        *(double*)(array+i) = 1.0;

is not safe. An example of a dangerous array would be an array of
"struct { char buf[9]; }".
 
> why not? lets say pointer is 8bytes, by rounding up size to next multiple
> of 8, we get good alignment, don't we? If we really don't risk, we can
> round up to 16, which is what malloc does. then alignment issues would be
> no way worse than with malloc().

As far as I understand, you want to stuck a pointer in an element of
an array. If you mean that the relative position of a pointer inside
the element will vary depending on the element size and index, then
yes, you can do it. However, this sounds like an ugly hack that is not
worth the benefits. Again, I may be misinterpreting your intentions.

Alex.
Received on Fri Oct 27 2000 - 17:34:07 MDT

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