Any way to track memory allocations?

wade swadenator at gmail.com
Tue Feb 24 17:04:22 PST 2009


Thanks again for all the help.  I found what the problem was and it wasn't obvious (at least to me):

float[uint] arr;

foreach (uint k; arr.keys)
{
 ...
}

Changing this to:

foreach (uint k, float v; arr)
{
...
}

fixes the leak.  I guess the keys array is constructed on the fly?

wade

Lutger Wrote:

> Jarrett Billingsley wrote:
> 
> > On Tue, Feb 24, 2009 at 12:00 PM, wade Shen <swadenator at gmail.com> wrote:
> >> I'm writing some performance sensitive code (real time processing) for 
> which I've tried to minimize the number of memory allocations by using 
> preallocated objects pools.  Unfortunately, during the course of running, it 
> seems that lots of memory is still getting allocated even though all 
> explicit "new" and array slicing operations have been moved out of the main 
> processing loops.  As a result the program is quite slow when garbage 
> collection is enabled (but very fast otherwise).
> > 
> > Array slicing does not cause the GC to run.  It is essentially free,
> > which is a wonderful thing.
> > 
> >> Is there a way to track down where memory is being allocated if I'm using 
> phobos? Any recommendations would be appreciated.
> > 
> > This is something I have *always* wanted.  Unfortunately I don't think
> > it's possible to add such instrumentation without modifying and
> > recompiling Phobos.  Even if you're using D2, which uses druntime,
> > there's no such thing.
> 
> Might it be possible to use tangobos for this purpose and just add asserts 
> in the GC code? Last time I looked it was pretty straightforward to 
> recompile Tango. 
> 



More information about the Digitalmars-d-learn mailing list