* malloc() wierdness
@ 1995-09-24 4:00 Benny Holmgren
1995-09-25 4:00 ` Timothy M. Wieman
0 siblings, 1 reply; 2+ messages in thread
From: Benny Holmgren @ 1995-09-24 4:00 UTC (permalink / raw)
Hello.
I'm having trouble to allocate memory with malloc() under alpha/osf1 2.1.
I'm getting the following message to stderr. Can anyone explain to me what's
going on?
Regards,
Benny
--------------------------- Error message follows --------------------------
Unaligned access pid=11504 <Xsh> va=1400c5041 pc=3ff801297a8 ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c5082 pc=3ff801297ac ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c5051 pc=3ff801297c4 ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c5051 pc=3ff801297cc ra=3ff80129334 type=stq
Unaligned access pid=11504 <Xsh> va=1400c5041 pc=3ff801292c8 ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c5049 pc=3ff80129324 ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c5051 pc=3ff80129328 ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c5082 pc=3ff801292c8 ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c508a pc=3ff80129324 ra=3ff80129334 type=ldq
Unaligned access pid=11504 <Xsh> va=1400c5092 pc=3ff80129328 ra=3ff80129334 type=ldq
--
Benny Holmgren bigfoot@astrakan.hgs.se
Astrakan Computer Club tel. +46-(0)26-183573
Sweden "It's not about length, it's shoesize"
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: malloc() wierdness
1995-09-24 4:00 malloc() wierdness Benny Holmgren
@ 1995-09-25 4:00 ` Timothy M. Wieman
0 siblings, 0 replies; 2+ messages in thread
From: Timothy M. Wieman @ 1995-09-25 4:00 UTC (permalink / raw)
Benny Holmgren (bigfoot@Astrakan.HGS.SE) wrote:
: Hello.
: I'm having trouble to allocate memory with malloc() under alpha/osf1 2.1.
: I'm getting the following message to stderr. Can anyone explain to me what's
: going on?
: Regards,
: Benny
: --------------------------- Error message follows --------------------------
: Unaligned access pid=11504 <Xsh> va=1400c5041 pc=3ff801297a8 ra=3ff80129334 type=ldq
: Unaligned access pid=11504 <Xsh> va=1400c5082 pc=3ff801297ac ra=3ff80129334 type=ldq
: .....
: --
: Benny Holmgren bigfoot@astrakan.hgs.se
: Astrakan Computer Club tel. +46-(0)26-183573
: Sweden "It's not about length, it's shoesize"
You're trying to access memory that isn't aligned on a boundary. When
memory is allocated (both automatically and explicitly) it is allocated
on a boundary. Correct me if I'm wrong, but the alignment is as
follows:
char - 1 byte
short - 2 byte
int,float - 4 byte
long,double,pointer - 8 byte
For example, a structure defined as:
struct teststru {
char ch;
long testlong;
};
has wasted 7 bytes of space, because the long must be allocated on an
8 byte boundary (the memory address must be divisible by 8). The size
of this struct is 16 bytes.
The following code fragment will give an unaligned memory access error:
char buf[20];
int *intptr;
intptr = (int*) &buf[1];
printf("%d\n", *intptr);
because the printf statement accesses an int which isn't on a 4 byte
boundary. Changing the assignment of intptr to: intptr=(int*)&buf[4]
will fix the unaligned access.
Hope this helps. Tim
--
------------------------------------------------------------------------
Timothy M. Wieman | Software Engineer
|
timw@hces.com | PACE Health Management Systems, Inc.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1995-09-25 4:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1995-09-24 4:00 malloc() wierdness Benny Holmgren
1995-09-25 4:00 ` Timothy M. Wieman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox