From: "Orasanu Iuliana" <[EMAIL PROTECTED]>
> pDBName = (char**)MemPtrNew( sizeof( char*)*2); // i'm allocating memory
for only 2 fields,
> Char *name;
> // then... in a while rutine:
>
> name = (char*)MemPtrNew(appInfo.nameBufLen);
Perhaps this needs to be appInfo.nameBufLen + 1?  A buffer overrun might
trash the start of the next block on the heap, possibly confusing the OS.

> StrCopy(name,appInfo.nameP);
> pDBName[*row]=name;

Shouldn't this be pDBName[index]=name; ? (although I don't think that
on it's own would produce a problem unless *row wasn't valid).  I also
wouldn't have thought that you need the 'name' variable, since you could
save directly into pDBName[].  Which leads to the question as to whether
you need to resize the array before you store the new pointer, although
it looks like you're always keeping an empty position at the end of the
array.

What can help to reduce memory fragmentation with this sort of logic is
resizing in units of ten or twenty.  You have to store the arraysize and
current element count separately, but it avoids the repeated resizing
involved with this approach.  If you're worried about wasted space you
can always finish by resizing the array to the final size.

> index++; // this keeps the curent no of fields allocated

> if (index >2)
>     MemPtrResize ( pDBName, sizeof(char*)*index); // the error that i'm
caching here is "memory locked", but in the documations I read: "Call this
routine to resize a locked chunk. "
>
Yeah, I never understood why a Ptr API call would return a locked
error, but my guess was that it was an old doc error, or a side-effect
of the low-level code that handles ptrs and chunks.

Chris Tutty


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

Reply via email to