Best memory management D idioms
XavierAP via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Mar 7 17:15:19 PST 2017
On Tuesday, 7 March 2017 at 18:21:43 UTC, Eugene Wissner wrote:
> To avoid this from the beginning, it may be better to use
> allocators. You can use "make" and "dispose" from
> std.experimental.allocator the same way as New/Delete.
OK I've been reading on std.experimental.allocator; it looks
really powerful and general, more than I need. I see the
potential but I don't really have the knowledge to tweak memory
management, and the details of the "building blocks" are well
beyond me.
But even if I don't go there, I guess it's a good thing that I
can change my program's allocator by changing one single line or
version assigning theAllocator, and benchmark the results among
different possibilities.
I see the default allocator is the same GC heap used by 'new'.
Just for my learning curiosity, does this mean that if I
theAllocator.make() something and then forget to dispose() it, it
will be garbage collected the same once no longer referenced? And
so are these objects traversed by the GC?
I've also looked at mallocator, [2] can it be used in some way to
provide an allocator instead of the default theAllocator? As far
as I can tell mallocator is not enough to implement an
IAllocator, is there a reason, or where's the rest, am I missing
it?
[1] https://dlang.org/phobos/std_experimental_allocator.html
[2]
https://dlang.org/phobos/std_experimental_allocator_mallocator.html
More information about the Digitalmars-d-learn
mailing list