lkml.org 
[lkml]   [1998]   [Jul]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectRe: [linux-usb] Re: How to get aligned memory?
From
Date
"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

\
 
 \ /
  Last update: 2005-03-22 13:43    [W:0.092 / U:0.340 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site