Why is this increasing memory consumption on every iteration?

Timon Gehr timon.gehr at gmx.ch
Sun Jun 16 12:35:28 PDT 2013


On 06/16/2013 08:37 PM, Geancarlo Rocha wrote:
> ...
>>
>>> the current GC is unreliable, booo!
>>
>> No it is not. You are not even allocating GC-controlled memory during
>> the loop.
>>
>> This is a std.container.BinaryHeap issue. It never shrinks the
>> underlying container.
>>
>> http://d.puremagic.com/issues/
>
> If that is the case, I don't think that's something a beginner would
> figure out unless he went to look the source code.

That's what I have done. I consider the behaviour entirely unreasonable. 
You may report it using the link above.

> Coming from C#, even the idea that you have to pass a "store" to the
> BinaryHeap is weird to me.

You mean coming from the System.Collections namespace of the .NET 
framework. BinaryHeap is a library artefact.

> I also don't understand this:
>
> void toy()
> {
>      Array!(int) store;
>      auto minheap = new BinaryHeap!(Array!(int), "a > b")(store);
>      auto rng = new Random(unpredictableSeed);
>
>      assert( store.length == 0 );
>      writeln("inserting...");
>
>      for( uint i = 0 ; i < 100_000 ; i++)
>      {
>          minheap.insert(1);
>          assert( store.length == 0 );
>      }
>      writeln("done.");
>      assert( store.length == 0 );
>
>      writeln("removing");
>      while(!minheap.empty)
>      {
>          minheap.removeFront();
>          assert( store.length == 0 );
>      }
>      writeln("done.");
>      assert( store.length == 0 );
> }
>
> I thought the BinaryHeap would modify store's buffer AND it's
> properties, but it doesn't seem to be the case. How is store being used?

I'd guess a copy of store is used, since Array is a value type (using a 
ref-counted payload).

> Again this is the sort of thing that makes a beginner's learning curve
> steeper.
>

I wouldn't spend too much time on std.container. A sane collections 
library currently is not part of the standard distribution.

>
> Thanks for your attention



More information about the Digitalmars-d-learn mailing list