|
From: Nicholas N. <nj...@ca...> - 2003-12-03 12:38:15
|
I asked this:
> > The pointer returned if the allocation succeeds is suitably aligned so
> > that it may be assigned to a pointer to any type of object and then
> > used to access such an object or an array of such objects in the
> > space allocated (until the space is explicitly freed or
> > reallocated).
> >
> > I'm not sure what this actually means. For x86, does "suitably aligned"
> > have any meaning at all, since unaligned accesses are ok?
Jeremy said:
> Well, unaligned accesses are only OK by default. You can turn on
> alignment checking, and get faults on unaligned accesses. Also, SSE
> instructions have a 16-byte alignment requirement.
>
> we should 8-align at least, maybe even 16.
Dirk said:
> suitably aligned means naturally aligned for all sizes the processor
> supports. x86 expects doubles to be 8-aligned and some SSE stuff even 16
> aligned.
"Suitably aligned" is a phrase that gets used a lot, but I can't find a
formal definition -- does anyone have one? Dirk, where did you get your
definition from?
I looked in glibc to see what happens there... it has this comment:
Alignment: 2 * sizeof(size_t) (default)
(i.e., 8 byte alignment with 4byte size_t). This suffices for
nearly all current machines and C compilers. However, you can
define MALLOC_ALIGNMENT to be wider than this if necessary.
And in practice, glibc's malloc() seems to use 8-byte alignment.
----
So, Jeremy and Dirk both said "we should use 8-byte at least, and maybe
16-byte". I agree. Since glibc uses 8-byte, that seems the best choice.
Julian, do you have any complaints?
I guess the next question is: should this change be made in just HEAD, or
stable branch too? I vote for both.
N
|