Re: [linux-usb] Re: How to get aligned memory?

Richard B. Johnson (root@chaos.analogic.com)
Thu, 30 Jul 1998 13:44:56 -0400 (EDT)


On 30 Jul 1998, Michael Poole wrote:

> "Richard B. Johnson" <root@chaos.analogic.com> writes:
>
> > This can be done in one line, with one pointer, but I will do it
> > step-by-step....
> >
> > funny struct *bits;
> > char *foo, *bar;
> > foo = (char *) malloc(WHATEVER); /* Waste 16 bits */
> > bar = foo;
> > foo += 0x00000010;
> > foo &= 0xfffffff0;
> > bits = (funny struct *) foo;
> > ........
> > do stuff
> > free(bar);
>
> Actually, that's guaranteed to waste at least one byte. The allocation of
> foo only needs to grab 15 extra bytes, and the "foo += 0x10" should
> be "foo += 0x0f" -- if foo is magically aligned to a 16-byte offset before
> you get it, then there's very little point in shifting it up to the next
> 16-byte block.
>

Picky, picky. I wouldn't really do it either way because the compiler
will not allow binary operations upon a pointer. The idea was to
demonstrate the mechanism, i.e., allocate something big enough and
do the alignment yourself.

Cheers,
Dick Johnson
***** FILE SYSTEM MODIFIED *****
Penguin : Linux version 2.1.111 on an i586 machine (66.15 BogoMips).
Warning : It's hard to remain at the trailing edge of technology.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html