Re: Safely moving structs in D

2017-01-25 Thread bitwise via Digitalmars-d-learn
On Tuesday, 24 January 2017 at 11:46:47 UTC, Jonathan M Davis wrote: On Monday, January 23, 2017 22:26:58 bitwise via Digitalmars-d-learn wrote: [...] Moving structs is fine. The postblit constructor is for when they're copied. A copy is unnecessary if the original isn't around anymore -

Re: Safely moving structs in D

2017-01-24 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 23, 2017 22:26:58 bitwise via Digitalmars-d-learn wrote: > Is it ok to memcpy/memmove a struct in D? > > Quote from here: > https://dlang.org/spec/garbage.html > > "Do not have pointers in a struct instance that point back to the > same instance. The trouble with this is if the

Re: Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
On Monday, 23 January 2017 at 23:04:45 UTC, Ali Çehreli wrote: On 01/23/2017 02:58 PM, bitwise wrote: I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not:

Re: Safely moving structs in D

2017-01-23 Thread Ali Çehreli via Digitalmars-d-learn
On 01/23/2017 02:58 PM, bitwise wrote: I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not: https://github.com/dlang/phobos/blob/04cca5c85ddf2be25381fc63c3e941498b17541b/std/container/array.d#L884 Post-blit is

Re: Safely moving structs in D

2017-01-23 Thread sarn via Digitalmars-d-learn
On Monday, 23 January 2017 at 22:26:58 UTC, bitwise wrote: Is it ok to memcpy/memmove a struct in D? Quote from here: https://dlang.org/spec/garbage.html "Do not have pointers in a struct instance that point back to the same instance. The trouble with this is if the instance gets moved in

Re: Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
I'm confused about what the rules would be here. It would make sense to call the postblit if present, but std.Array currently does not: https://github.com/dlang/phobos/blob/04cca5c85ddf2be25381fc63c3e941498b17541b/std/container/array.d#L884

Safely moving structs in D

2017-01-23 Thread bitwise via Digitalmars-d-learn
Is it ok to memcpy/memmove a struct in D? Quote from here: https://dlang.org/spec/garbage.html "Do not have pointers in a struct instance that point back to the same instance. The trouble with this is if the instance gets moved in memory, the pointer will point back to where it came from,