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

Rogier Wolff (R.E.Wolff@BitWizard.nl)
Fri, 31 Jul 1998 08:58:37 +0200 (MEST)


Richard B. Johnson wrote:
> 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.

P.S. Malloc usually returns 16-byte aligned stuff. (At least when I
wrote the darn thing :-)

Roger.

-- 
Actor asks a collegue: "To what do you owe your success in acting?"
Answer: "Honesty. Once you've learned how to fake that, you've got it made."
-------- Custom Linux device drivers for sale! Call for a quote. ----------
Email: R.E.Wolff@BitWizard.nl || Tel: +31-15-2137555 || FAX: +31-15-2138217

- 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