[Issue 16131] A struct is being copied unnecessarily when initialized

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Wed Jun 8 08:08:01 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16131

Steven Schveighoffer <schveiguy at yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |schveiguy at yahoo.com

--- Comment #5 from Steven Schveighoffer <schveiguy at yahoo.com> ---
(In reply to Eyal from comment #3)

>         fib = new Fiber(&run);

This is your problem. This stores a context pointer to 'this', which may
change.

In general, it's a bad idea to use delegates to structs unless you know they
won't move (e.g. part of a heap allocation).

Ketmar is right that it's perfectly valid to memcpy a struct in D. You have to
expect that.

--


More information about the Digitalmars-d-bugs mailing list