Re: How to get aligned memory?

Richard B. Johnson (root@chaos.analogic.com)
Thu, 30 Jul 1998 09:46:14 -0400 (EDT)


On Thu, 30 Jul 1998, Inaky Perez Gonzalez wrote:

>
> Hi
>
> This is a so silly question I feel dumb for not having able to
> find it myself ... how can I get aligned memory?
>
> The problem is I have this structure, 64 bits long which needs
> to be aligned to 16 bytes (thx, Intel >:), but I cannot find my to do
> it (except to allocate a lot until I get it aligned, which is quite
> wasteful :).
>
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);

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