Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: David Hagood <wowbagger@sktc.net>
Subject: Re: Dealing with unaligned accesses
Date: 1998/12/09	[thread overview]
Message-ID: <366E7769.4B6FF2D@sktc.net> (raw)
In-Reply-To: 36673795.6C675A97@netcom.com

> access occurs.  The data item at that address is an eight byte pointer.
> The first byte of the structure is at address 2017fbd4.  This means that
> moving the pointer to the top of the structure won't help.  In fact, the
> structure is an even number of 64 bits in length.

First, re-order the structure so that it allocates the biggest items first:
pointers and arrays, then shorts, then chars.

Second, modify the malloc call to look something like this:

foo *my_pointer;
void *save_ptr;
save_ptr = malloc(sizeof(foo)+8);
my_pointer = (foo *)(((unsigned long)save_ptr+7)&(~7));

This will force the actual pointer to be qword aligned no matter what
malloc returns. There is one gotcha: you cannot free my_pointer, you must
free save_ptr.

Malloc ought to return aligned memory; perhaps there's a bug in libc/glibc.






      reply	other threads:[~1998-12-09  5:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-03  5:00 Dealing with unaligned accesses Oscar Levi
1998-12-09  5:00 ` David Hagood [this message]
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox