[fpc-pascal] collection memory usage...

Tomas Hajny XHajT03 at hajny.biz
Sat Oct 27 22:23:41 CEST 2012


On Sat, October 27, 2012 21:33, waldo kitty wrote:

> i'm trying to figure out the best numbers to use for setting up a sorted
> collection... i'm just not understanding the numbers i'm getting from the
> heapdump unit at the end of the run...
>
> i have two collections (/details at the end/)... these collections can be
> pretty
> "large" (~40000 entries for one collection, ~20000 for the other)... using
> the
> *exact same data* in both cases, if i use this code to set them up...
>
>    aTLEColl    := New(PTLEColl, Init(16384,64));
>    aSatCatColl := New(PSCColl, Init(16384,64));
>
> i get numbers like this (from the heapdump)
>
>    Heap dump by heaptrc unit
>    8205341 memory blocks allocated : 333112907/357222392
>    8205341 memory blocks freed     : 333112907/357222392
>    0 unfreed memory blocks : 0
>    True heap size : 720896 (208 used in System startup)
>    True free heap : 720688
>
> but if i use this code to set up the collections...
>
>    aTLEColl    := New(PTLEColl, Init(1,1));
>    aSatCatColl := New(PSCColl, Init(1,1));
>
> i get numbers like this (from the heapdump)
>
>    Heap dump by heaptrc unit
>    8260386 memory blocks allocated : 3874244611/3898464904
>    8260386 memory blocks freed     : 3874244611/3898464904
>    0 unfreed memory blocks : 0
>    True heap size : 262144 (208 used in System startup)
>    True free heap : 261936
>
> *if i'm reading this properly*, what is confusing me is the first one
> allocates
> less memory blocks and uses more heap whereas the second one allocates (a
> lot)
> more memory blocks (55000 more??) but uses much less heap...

The number of blocks is higher in the second case because a new memory
block is allocated for each record added to the collection (initial
collection size is 1, the size is increased by one record whenever the
allocated size is fully used and a new record shall be added). However,
I'm not clear why you think that less heap is used in the second case?


> so i'm trying to figure out the best set of init numbers for the
> collections...
> i'm wanting the fastest run time with the smallest memory usage... am i
> understanding this correctly??

Considering the number of records you suggested above, I'd go for
something like 20000 records as the initial collection size and e.g. 2000
or even 5000 as the increment.

Tomas





More information about the fpc-pascal mailing list