Overload new and delete to not use GC?

Basile B. via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun May 22 02:45:32 PDT 2016


On Sunday, 22 May 2016 at 07:35:32 UTC, Rusty wrote:
> I know it's possible to do [explicit object 
> allocation](http://wiki.dlang.org/Memory_Management#Explicit_Class_Instance_Allocation) on the heap, but I find that quite cumbersome.
>
> So.. is it possible to overload 'new' and 'delete' to not use 
> GC?

use the Mallocator with make and dispose:

import std.stdio;
import std.experimental.allocator: make, dispose;
import std.experimental.allocator.mallocator: Mallocator;

class Foo{}

void main(string[] args)
{
     Foo foo = make!Foo(Mallocator.instance);
     dispose(Mallocator.instance, foo);
}

> Also, it seems many features of the language rely on GC. Is 
> there a definitive list of those ?

If you use DMD as compiler the switch -vgc can help to track GC 
allocations.


More information about the Digitalmars-d-learn mailing list