struct on heap with std.experimental.allocator

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jun 7 08:43:34 PDT 2016


On Tuesday, 7 June 2016 at 15:39:59 UTC, jmh530 wrote:
> My sense is that putting it on the GC heap gives the struct 
> reference semantics.

It doesn't matter what heap it is on, you are just using a 
pointer here.

Struct pointers in D will automatically dereference with a.x, so 
no need for the * there (in most cases), and assigning it to 
another pointer of course still points to the same object, so it 
will affect both.

If you want a copy, you can use a special method to allocate a 
new one or use auto a = *b; which will copy it to the stack.


More information about the Digitalmars-d-learn mailing list