Messages in this thread | | | Subject | Re: [linux-usb] Re: How to get aligned memory? | From | Michael Poole <> | Date | 30 Jul 1998 12:30:18 -0400 |
| |
"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.
-- Michael
- 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
| |