www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Placement New

reply JRM <a b.com> writes:
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
Jul 04 2010
parent reply bearophile <bearophileHUGS lycos.com> writes:
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
Jul 04 2010
parent reply JRM <a b.com> writes:
 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.
Jul 04 2010
parent bearophile <bearophileHUGS lycos.com> writes:
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
Jul 04 2010