Are D classes always garbage collected?

Vladimir Panteleev vladimir at thecybershadow.net
Wed Dec 21 22:57:08 PST 2011


On Thursday, 22 December 2011 at 06:43:33 UTC, Froglegs wrote:
>
>> T emplace(T, Args...)(void[] chunk, Args args) if (is(T == 
>> class))
>> {
>> enforce(chunk.length >= __traits(classInstanceSize, T),
>>        new ConvException("emplace: chunk size too small"));
>> ...
>>
>> This fails whenever the size is greater or equal to the amount 
>> of memory required :(
>
> Hum nevermind that, got confused by the IDE behavior.  Anway 
> this emplace function crashes when I call it with a very 
> meaningless callstack.

This works for me:

import std.conv;
class C {
   int i;
   this() { i = 42; }
}
unittest {
   void[__traits(classInstanceSize, C)] data = void;
   auto c = emplace!C(data[]);
   assert(c.i == 42);
}



More information about the Digitalmars-d-learn mailing list