std.experimental.allocator API and nearly useless StatsCollector

Basile B. b2.temp at gmx.com
Sun Jun 20 16:53:06 UTC 2021


On Sunday, 20 June 2021 at 15:49:13 UTC, Luis wrote:
> Well, this last week I was playing using malloc/free to do some 
> @nogc code, and using the std.experimental.allocator API. Also, 
> I was trying to see a way to profile my code and search for 
> memory leaks, etc...
>
> [...]
>
> The stats that are reported by reportPerCallStatistics, shows 
> the file & line number of the allocator!
>
> Like this :
>
> ```
> /usr/include/dmd/phobos/std/experimental/allocator/package.d(1585): [numAllocate:1, numAllocateOK:1, bytesAllocated:40]
> ```
>
> This could be useful for someone writing his own allocator, but 
> it's pretty useless for anyone trying to track where a memory 
> leak originated in his own code!


To understand leaks I'd use valgrind instead. As it is based on 
DWARF info, reported leaking blocks are accompanied with a pretty 
(after demangling) back trace. So the first entry for each block 
will be unsurprinsingly always the same (e.g glibc malloc) but 
the other can be more interesting.


More information about the Digitalmars-d mailing list