Messages in this thread | | | Date | Mon, 20 Oct 2008 08:54:44 -0600 | From | "Chris Friesen" <> | Subject | Re: [Slightly off topic] A question about R/B trees. |
| |
Maxim Levitsky wrote:
> Say you allocate a piece of memory using kmalloc, and write there, a > structure that contains a r/b tree item. I agree that gcc will ensure > that offset from start of that structure to first byte of the tree > item will be aligned. > > But what if malloc returned a misaligned pointer? This will ensure > that virtual address of the tree item won't be aligned. (I know it > doesn't, but this isn't a assumption about gcc anymore)
malloc() can't return a misaligned pointer. From the spec: "The pointer returned if the allocation succeeds shall be suitably aligned so that it may be assigned to a pointer to any type of object..."
Chris
| |