Re: How to get aligned memory?

Tom Vier (nester@sekurity.org)
Thu, 30 Jul 1998 20:35:50 -0400 (EDT)


there's also an example in the man page for mprotect

> > 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);

--
Tom Vier - 0x82B007A8    | Hate Micro$hit, AOLame, and Untel?
thomassr@erols.com       | Then goto the Zero Page at:
Tortured Souls Software  | http://www.erols.com/thomassr/zero/

- 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