Thread overview
Placement New
Jul 04, 2010
JRM
Jul 04, 2010
bearophile
Jul 04, 2010
JRM
Jul 04, 2010
bearophile
July 04, 2010
Does placement new work yet, or am I using it wrong?

import std.c.stdlib;

class Foo {}
void main() {
   Foo f = new(malloc(Foo.sizeof)) Foo();
}

With dmd 2.047: Error: no allocator for Foo
July 04, 2010
JRM:
> Does placement new work yet, or am I using it wrong?

Take a look here: http://www.digitalmars.com/d/2.0/memory.html

But I think that part of D2 will change because Andrei doesn't like it, it will removed and it will be replaced by something I don't understand yet.

Bye,
bearophile
July 04, 2010
> Take a look here: http://www.digitalmars.com/d/2.0/memory.html
> 
> But I think that part of D2 will change because Andrei doesn't like it, it will removed and it will be replaced by something I don't understand yet.
> 
> Bye,
> bearophile

I didn't see anything on that page referring to placement new.  I also thought I remembered seeing something about class allocators going away too.  TDPL doesn't mention allocators and only briefly mentioned placement new, so I wasn't sure if I was just using it incorrectly or if it is one of those planned but not fully implemented features.  It seems to be looking like the latter.
July 04, 2010
JRM:
> I didn't see anything on that page referring to placement new.

I think the new() and delete() standard methods are (were) the D way to allocate the memory of a class instance where you want.

Bye,
bearophile