Your code appears OK except for the call to MemPtrFree.  DmQueryRecord doesn't 
allocate any memory -- it just returns a reference to an already-existing record.  
MemHandleLock doesn't allocate any memory -- it just ensures that a relocatable memory 
chunk doesn't move around as the heap is compacted.  So, since you don't allocate any 
memory, there's no need to dispose of it with MemPtrFree.

BTW, keep in mind that DmQueryRecord returns a read-only reference to the record.  You 
can read from it but you can't update it.  If you want to update the record, you need 
to call DmGetRecord instead.  If you do that, then you need to later release the 
record with DmReleaseRecord when you're done with it.

-- Keith

> -----Original Message-----
> From: Barnett, Phil R
> Sent: Wednesday, November 19, 2003 11:58 AM
> To: Palm Developer Forum
> Subject: Sequential record handling question
> 
> Does the following code handle memory allocation correctly 
> for skipping
> through every record of a table?
> 
> Does MemHandleLock() return a memory pointer? Do I need a recP =
> MemPtrNew(sizeof(mydataDB)); somewhere?
> 
> Thanks.
> 
> 
> mydataDBPtr recP;
> UInt16   i, numRecs;
> MemHandle  recH;
> 
> numRecs = DmNumRecords(gDB);
> 
> for (i=0; i < numRecs;i++) {
>     recH = DmQueryRecord(gDB, i);
>     if (recH) {
>         recP = (mydataDBPtr)MemHandleLock(recH);
>     }
>      
>     // lots of record oriented code here
> 
>     if (recH) {
>         MemHandleUnlock(recH);
>         MemPtrFree(recP);
>     }
> }

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

Reply via email to