You are correct -- the pointers are not guaranteed to be valid after you
unlock the handles.  You should either use MemHandle in your struct (instead
of char*), or use MemPtrNew instead of MemHandleNew.  The second option is
simpler, and more efficient in terms of execution speed.  However, the first
option is more "memory conscious," especially if you are keeping the memory
allocated for a long time.


Eric W. Sirko
Softworks Solutions, LLC


> I have a data structure declared for my App, with mostly Char*'s as
members:
>
> typedef structure {
> bool mybool;
> char* one;
> char* two;
> char* three;
> } MyStruct;
>
> Say one function gets a memory chunk using MemHandleNew, copies a string
into
> it, and points MyStruct->one at it. Repeat the process for two and three
all in
> the following manner:
>
> MyStruct struct = MemHandleNew(sizeof(MyStruct));
> Char* src = "test";
> MemHandle tmpH = MemHandleNew(StrLen(s)+1);
> s = MemHandleLock(tmpH);
> struct->one = s;
> MemHandleUnlock(tmpH);
>
> I then pass the struct onto another function. Those char* in the struct
won't be
> valid, since I didn't keep the Handles locked after setting the Char* to
point
> at the string, correct?
>
> If this is the case, is it better to use MemHandles in the struct instead
of
> char*'s? What's the 'normal' way to handle this?
>
> TIA, hope it's not too stupid of a question, first Palm App.
>
> Steve Cochran
>
>
>



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

Reply via email to