[fpc-pascal] collection memory usage...

Tomas Hajny XHajT03 at hajny.biz
Sun Oct 28 02:01:11 CEST 2012


On Sat, October 27, 2012 22:56, waldo kitty wrote:
> On 10/27/2012 16:23, Tomas Hajny wrote:
> [trim]
>>> *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).
>
> ahhh... ok, so that's "number of records" to start with and "number of
> records
> to increase by"...

Indeed, as described in our documentation (in particular part related to
TCollection.Init in unit Objects - quoted including the typo there ;-) ):

Declaration: constructor Init(ALimit: Sw_Integer;ADelta: Sw_Integer)
Visibility: default
Description: Init initializes a new instance of a collection. It sets the
(initial) maximum number of items in the collection to ALimit. ADelta is
the increase size : The number of memory places that will be allocatiod in
case ALimit is reached, and another element is added to the collection.

TSortedCollection.Init uses the same parameters with the same meaning as
constructor of its ancestor.


>>> However, I'm not clear why you think that less heap is used in the
>>> second case?
>
> because "true heap size" is different between them... i am thinking that
> this is
> the total amount of heap used by the program during its run??

No, it's just the amount of memory allocated for heap at the given point
in time. The real amount of memory used must be much higher obviously (the
number of records you mentioned multiplied by pure size of the stored data
already gives a bigger number even without counting any overhead for
storing all the pointers, VMT tables, etc.).


 .
 .
> FWIW: i had asked this some several months back but was probably not as
> clear in
> my request... it may have also been in the wrong area but i didn't get any
> response to it so i just left it alone to ask later ;)

Well, there may be various reasons for not getting responses. I don't
remember having seen such a message so I personally probably missed it for
whatever reason. Not so many people use (or even know) the original TP/BP
object model and the objects included in our RTL nowadays so that may also
impact the response rate. In any case, asking again and possibly
reformulating the question a bit never hurts. ;-)

Tomas





More information about the fpc-pascal mailing list