Bill,
When you use MemHandleNew() the handle that is allocated is in the dynamic heap. The
dynamic heap is freed when your application exits, so attaching such a handle to a
database will corrupt that database.
Instead of using MemHandleNew(), use DmNewHandle(). This allocates the handle in
database memory, ensuring that it can safely be attached to your database. It won't be
freed when your application exits.
-Bob Whiteman
=====================
Developer Technical Services Engineer - Comms
PalmSource, Inc.
=====================
-----Original Message-----
From: Bill Heidler [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 15, 2003 6:17 PM
To: Palm Developer Forum
Subject: DmAttachRecord, DmResizeRecord problems
I am starting to develop the DB part of my app; I have records that are
linked
and some potential performance issues, such that I want my record indexes
to be stable (records will not change index value or be deleted except
during
HotSync). However, the records may be updated and change in size (shrink
or expand). Records will typically be several hundred bytes or less, but
could
potentially be much larger. I would like to impose as few restrictions on
the
record sizes as possible.
When a record is updated, the old data will be completely replaced by the
new
data.
My first solution approach for updating the records was to use
DmResizeRecord()
to reduce the size of the old record (to 0 if possible, thus holding my
record slot
only), allocate a memory buffer using MemHandleNew() ), stuff it with the
new data
and then use DmAttachRecord() to replace the old record chunk. Problem is,
when I exit the app I get a Memory Leak detected for the chunk that I
allocated and
attached. I like the Memory Leak detection feature of the POSE, so don't
want to
have to ignore messages like that (and I'm not sure what the ramifications
would be
on the device anyway).
Second solution approach is to do another DmResizeRecord() instead of the
DmAttachRecord(), then copy the data from the memory buffer and then delete
the buffer. That gets rid of the memory leak, but when I did this I got a
Chunk
Locked error on the second DmResizeRecord(). I didn't seem to get the error
all the time, but could not pin down the circumstances when I got it and
when I
didn't.
The workaround to that is to unlock the chunk associated with the record
(the
handle that gets returned from the first DmResizeRecord() call). That seems
to work; but I worry that the chunk is not being locked all the time. I
have gotten
Chunk Underlocked errors from the MemHandleUnlock() once or twice. Again,
I haven't tested enough to pin down the circumstances.
I am running PalmOS v 3.5.1, using CodeWarrior 8.0 .
Thank you for any help or comments,
Bill Heidler
< [EMAIL PROTECTED] >
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/