Current state of "D as a better C" (Windows)?
Jakob Ovrum
jakobovrum at gmail.com
Sat Jan 25 22:10:46 PST 2014
On Sunday, 26 January 2014 at 05:17:35 UTC, Frank Bauer wrote:
> @Adam: thanks for pointing out _d_newclass for me. But for
> classes I would just simply use custom allocators and
> deallocators and use new and delete as in C++.
Aye, I don't recommend overloading `new` to mean something else.
Currently `new` = GC allocation, and code can rely on that.
Better to have such code break (by not defining _d_newclass) than
silently leak or worse.
> Leaves dynamic arrays and the rest of Phobos (which parts?)
> which I have to forego if I don't like GC (but I do like slices
> so much, not much left for me to slice then ...). And no,
> anonymous, it's not just reallocating or appending to arrays,
> every dynamic array is allocated on the GC'd heap from the
> start.
Huh? You can slice any pointer:
---
T[] allocArray(T)(size_t num)
{
if (auto chunk = cast(T*)calloc(num, T.sizeof))
return chunk[0 .. num];
else
onOutOfMemoryError();
}
---
As well as fixed-length arrays:
---
char[128] buffer = ...;
auto myStackString = buffer[0 .. len];
---
Slices are plenty useful without GC.
More information about the Digitalmars-d
mailing list