Are D classes always garbage collected?

Steven Schveighoffer schveiguy at yahoo.com
Sat Jan 7 09:14:10 PST 2012


On Thu, 22 Dec 2011 00:01:53 -0500, Vladimir Panteleev  
<vladimir at thecybershadow.net> wrote:

> On Thursday, 22 December 2011 at 04:15:25 UTC, Froglegs wrote:
>>
>>>> You can allocate classes anywhere, if you're OK with forfeiting  
>>>> safety guarantees. For example, see emplace in std.conv:
>>>>
>>>> http://dlang.org/phobos/std_conv.html#emplace
>>
>> Hum calling emplace ending up calling this bit of code..
>>
>> T* emplace(T)(T* chunk)
>>   if (is(T == class))
>> {
>>   *chunk = null;
>>   return chunk;
>> }
>>
>> Which returned me a nice fat null pointer.. wth? Perhaps that should be  
>> a compile time error if you aren't supposed to use classes..
>
> Strange... I'm not sure what the deal is with that overload. I meant the  
> last one on the page (that takes a void[]).

I see it, you are emplacing a class reference *pointer*, not a class  
reference.

Just so you know, classes are references already, you don't need to use  
pointers.

-Steve


More information about the Digitalmars-d-learn mailing list