Well my original test code looked like this:
CharPtr p1;
p1 = (CharPtr) MemPtrNew(1);
p1 = (CharPtr) MemPtrNew(2); // yes I know this leaks
p1 = (CharPtr) MemPtrNew(3);
etc etc...
It seems like for storing a bunch of short strings (1-10 characters in
length) in dynamic memory, it's a lot more efficient to MemPtrNew(100), and
then just move the strings around inside of that block, growing it as
necessary. Wasting 8-15 bytes in padding for 10-20 strings gets pretty
costly after a while.
-Jeff
> -----Original Message-----
> From: Fitzpatrick, Joe [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 24, 2000 5:55 PM
> To: Palm Developer Forum
> Subject: RE: Why does MemPtrNew(1) eat up 16 bytes?
>
>
> Are you doing this in a loop (for (x = 1 ; ...)) or one run at a time?
>
> -jjf
>
> -----Original Message-----
> From: Jeff Ishaq [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 24, 2000 1:26 PM
> To: Palm Developer Forum
> Subject: Why does MemPtrNew(1) eat up 16 bytes?
>
>
> Well this is interesting. Check out this data:
>
> The environment:
> CW6 on POSEr 3.0a3. Identical results were obtained using
> the 3.0 debug
> and
> 3.0 release ROM images from Palm's webpage.
>
> The test code:
>
> MemHeapFreeBytes(0, &freeInitial, &max);
> CharPtr pTest = (CharPtr) MemPtrNew(x);
> MemHeapFreeBytes(0, &freeFinal, &max);
> delta = freeInitial - freeFinal;
>
> x <- next value // pseudocode
> repeat test code // pseudocode
>
> The results:
> x delta excess padding
> 1 16 15
> 2 10 8
> 3 14 11
> 4 12 8
> 5 14 9
> 6 18 12
> 7 16 9
> 8 16 8
> 9 18 9
> 10 18 8
> 20 28 8
> 30 38 8
> 40 48 8
>
>
> Can someone explain what's going on here? Am I doing something silly?
> I
> see that each chunk has the overhead of its own
> MemChunkHeaderType (I'm
> guessing this takes up 8 bytes, or two DWords). I also assume DWord
> alignment to be considered. But I can't put a finger on
> exactly what's
> going on, especially with x=1, 3, and 6.
>
> This is so much fun!
> -Jeff
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palm.com/devzone/mailinglists.html
>
> --
> For information on using the Palm Developer Forums, or to
> unsubscribe, please see http://www.palm.com/devzone/mailinglists.html
>
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palm.com/devzone/mailinglists.html