What is the correct way to save a reference to a chunk of storage memory, in
a database field?  I read Article 2029 in the Knowledge Base and it seemed
like the correct way was to use DmNewHandle to allocate a chunk of storage
memory, then MemHandleLock to lock down a pointer to it, then DmWrite or
DmSet or DmStrCopy to write to the chunk - it is a character string.  Then
use MemHandleToLocalID and MemHandleCardNo to get the LocalID and card# of
the handle.  Then I save the localID and card# in database fields, and
MemHandleUnlock the handle.  Then when I want to use the string I stored, I
use MemLocalIDToGlobal to convert the localID/card# to a handle, then
MemHandleLock a pointer to the chunk.

This seemed to work for OS 3.1.  I am using OS 3.5 now.  I have used the
debugger on the device (kyocera 6035) and the problem is that after a soft
reset, the contents of the character string are not at the same address as
when I saved it, but the handle doesn't seem to get updated the way I
thought the OS was supposed to update it if it moves a chunk.  When I get to
the code where I want to use the contents of the chunk, I read the localID
and card# database fields, then use MemLocalIDToGlobal and get the same
value for the handle as before.  I did not see that localID or handle value
listed in any heap dump.  So I get a "free handle" error when I try to do
the MemHandleLock of the handle I get from the MemLocalIDToGlobal call.
When I try to view memory for the handle variable, I get a bus error from
the debugger.

This problem does not happen until after a soft reset of the device.  I
opened the debug console and did an hd 0, but did not see the chunk, so I
did an hd 1 and it was in that heap.  As expected, the heap dump flags
indicate that it is an allocated, movable chunk.  Also, the hd 1 showed it
as being locked even after I unlocked it in my code.

I thought I read through the Palm OS 3.5 info, but do not remember seeing an
issue with this.  What is the correct way to save a reference to a chunk of
storage memory in a database?  The string data I am storing can be of
variable length, so I wanted to avoid having a database field of some large
fixed length character array.

I would appreciate any insight - there are many many places in my code where
I store a localID/card# of a handle to a chunk of storage memory in a
database; this is just the first occurrence in my app's execution; I imagine
I will have this problem for all of the handles I use this way.

Karen Serafino


-- 
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