> Yes, I've checked that the memory leaks are from my database. The thing is
> that if a do a MemHandleNew and then need to "free" it up, and when I do
> that I lose my data. If I don't I get the memory leak.
> 
> Does anyone have an example where the database uses Char*? I'm really losing
> all hope :(
> 
> 
> Nicolas 

If you want to store data into a database, the call you want to use is
probably DmNewRecord, rather than MemHandleNew. 

As others have said, you can't store Char* variables into a database;
you need to store the strings that the Char* variables are pointing to
into the database. 

As a quick example, if you have three variables:

Char *a;
Char *b;
Char *c;

that you have pointing to some valid, null-terminated data, the way
you'd store this into a database record (in database db, which was
already open) is something like the following:

UInt16 len = StrLen(a)+1 + StrLen(b)+1 + StrLen(c)+1;
UInt16 indx = dmMaxRecordIndex;
MemHandle h = DmNewRecord(db, &indx, len);
if (h)
{
  Char *xx = (char *)MemHandleLock(h);
  if (xx)
  {
    UInt16 pos = 0;
    DmWrite(xx, pos, a, StrLen(a)+1);
    pos += StrLen(a)+1;
    DmWrite(xx, pos, b, StrLen(b)+1);
    pos += StrLen(b)+1;
    DmWrite(xx, pos, c, StrLen(c)+1);
    pos += StrLen(c)+1; // this really isn't necessary, but it's here
                        // for clarity
    MemHandleUnlock(h);
  }
  DmReleaseRecord(db, indx, true);
}

To read the variables from the database, you do something
similar. This is called packing and unpacking, and is a pretty common
way of storing strings into Palm databases.

Dean Gahlon

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

Reply via email to