struct on heap with std.experimental.allocator
jmh530 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 7 09:41:21 PDT 2016
On Tuesday, 7 June 2016 at 15:43:34 UTC, Adam D. Ruppe wrote:
> 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.
Thanks for the reply!
More information about the Digitalmars-d-learn
mailing list