Are D classes always garbage collected?
Andrew Wiley
wiley.andrew.j at gmail.com
Wed Dec 21 23:11:36 PST 2011
On Wed, Dec 21, 2011 at 10:20 PM, Froglegs <lugtug at gmail.com> wrote:
>
>>> 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[]).
>
>
>
> Hum I've tried the array version but I believe it contains a rather serious
> bug...
>
> 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 :(
>
>
> Anyway I need the pointer version for what I was hoping to do, unless there
> is some way to convert a pointer into an array?
>
> Is there any way to do something like this..
>
> void* pData = some_c_function();
> void [] fakeArray = pData, size;
>
>
Yes:
void* pData = some_c_function();
void[] fakeArray = pData[0..size];
Although Vladimir's solution is safer.
More information about the Digitalmars-d-learn
mailing list