I'm observing a very bizarre problem. Perhaps somebody else has encountered
it and can offer advice. I have a small function in a shared lib that looks
something like this:

void f( void )
{
BigStruct* structP = MemPtrNew(sizeof(BigStruct));

// code

SetFields(structP);

// more code

MemPtrFree(structP);
}

The function SetFields takes a pointer to a BigStruct as an input parameter,
then just grabs some data and fills in the fields of the structure. It
consists almost exclusively of lines like:

MemMove(structP->someField, data, nBytes);

structP itself is never touched or in any way changed in the function.

When I run this code on POSE or on a real, , Palm OS 4.x-based, non-Tungsten
device (I've tried a Vx, a m125, and a m515), it runs just fine. When I run
it on a Tungsten T (the only Tungsten model I have at the moment), bizarre
things happen. Looking at the code in the debugger, I can see that structP
is set to point at some reasonable looking place in heap memory after it's
initally assigned by the call to MemPtrNew. (BTW, the reason I'm putting the
struct on the heap and not on the stack is that it's big, over 1 KB, and I
don't want to run the risk of blowing the stack.) However, after the call to
SetFields, structP suddenly points to some other location altogether,
usually to a very low memory address. When I finally hit the call to
MemPtrFree, the whole program blows up and I get the message:

MemoryMgr.c, Line: 3650, non-word-aligned handle

Well, yeah. structP is pointing to some apparently random, wrong place. But
why is that?

Has anyone ever seen this before? Am I doing something fundamentally wrong?
If I am, how come this code works fine on Palm OS 4.x? Is this some weird
problem limited to Palm OS 5.0? Or maybe just the Tungsten T? I'd be very
grateful for any enlightenment.

BTW,  I'm using CW 9 as my dev env. AFAIK, I have installed all the latest
CW patches.

Thanks,
Jay

-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to