March 08, 2017 Re: Best memory management D idioms | ||||
---|---|---|---|---|
| ||||
Posted in reply to ag0aep6g | On Wednesday, 8 March 2017 at 06:42:40 UTC, ag0aep6g wrote: > [...] > > Yes and yes. GCAllocator.allocate calls core.memory.GC.malloc with does pretty much the same thing as the builtin `new`. Nitpicking: `new` is typed (i.e. allocation+construction), `malloc` and `allocate` are not (only allocation). If you want allocation *and* construction with the new Allocator interface, you'll want to use the make[1] (and dispose[2] for the reverse path) template function; and they are a superset of `new`: You cannot, e.g., construct a delegate with new, but you can with `make`. [1] https://dlang.org/phobos/std_experimental_allocator.html#.make [2] https://dlang.org/phobos/std_experimental_allocator.html#.dispose |
Copyright © 1999-2021 by the D Language Foundation