On 12/21/2011 10:20 PM, Froglegs 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 :(

That bug has recently been fixed:

  http://d.puremagic.com/issues/show_bug.cgi?id=6204

> 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?

emplace() with classes is a little more involved compared to structs; I think because the type of the class variable need not be the same type as the instance.

> Is there any way to do something like this..
>
> void* pData = some_c_function();
> void [] fakeArray = pData, size;

Yes, as Andrew Wiley has shown:

  void[] fakeArray = pData[0..size];

Ali

P.S. I have all of this in my Turkish book but that chapter hasn't been translated to English yet:

  http://ddili.org/ders/d/bellek_yonetimi.html

Reply via email to