digitalmars.D - Assuming structs are cheap to copy?
- Peter Alexander (9/9) Jan 09 2011 I remember there was a discussion a little while back about how Phobos
- Justin Johansson (7/16) Jan 10 2011 What if the byte size of some struct is say a KB or a MB would one still...
- Eric Poggel (4/22) Jan 10 2011 I assume it varies by architecture, but at what size threshold is it
- Jonathan M Davis (3/29) Jan 10 2011 No. dmd never turns things into ref unless you tell it to.
- Justin Johansson (4/13) Jan 10 2011 OTOH maybe I missed your point.
- Steven Schveighoffer (13/22) Jan 10 2011 The discussion was about assumptions that ranges will make on their
I remember there was a discussion a little while back about how Phobos would assume that structs are cheap to copy, and would simply pass them by value. Is this assumption now "the D way"? Should we all just pass structs by value, assuming cheap copy construction? If so, I think this needs to be documented somewhere (assuming it isn't already), because it's a radical departure from C++, and also from most other languages (where everything is a reference type). People need to be aware of this.
Jan 09 2011
On 10/01/11 03:06, Peter Alexander wrote:I remember there was a discussion a little while back about how Phobos would assume that structs are cheap to copy, and would simply pass them by value. Is this assumption now "the D way"? Should we all just pass structs by value, assuming cheap copy construction? If so, I think this needs to be documented somewhere (assuming it isn't already), because it's a radical departure from C++, and also from most other languages (where everything is a reference type). People need to be aware of this.What if the byte size of some struct is say a KB or a MB would one still think that copy construction is cheap? In this instance I would not blame poor performance on Phobos but rather than your own design. Cheers Justin
Jan 10 2011
On 1/10/2011 9:08 AM, Justin Johansson wrote:On 10/01/11 03:06, Peter Alexander wrote:I assume it varies by architecture, but at what size threshold is it faster to copy structs by reference instead of value? If I pass a large struct by value, will dmd optimize it away as a reference?I remember there was a discussion a little while back about how Phobos would assume that structs are cheap to copy, and would simply pass them by value. Is this assumption now "the D way"? Should we all just pass structs by value, assuming cheap copy construction? If so, I think this needs to be documented somewhere (assuming it isn't already), because it's a radical departure from C++, and also from most other languages (where everything is a reference type). People need to be aware of this.What if the byte size of some struct is say a KB or a MB would one still think that copy construction is cheap? In this instance I would not blame poor performance on Phobos but rather than your own design. Cheers Justin
Jan 10 2011
On Monday, January 10, 2011 10:52:40 Eric Poggel wrote:On 1/10/2011 9:08 AM, Justin Johansson wrote:No. dmd never turns things into ref unless you tell it to. - Jonathan M DavisOn 10/01/11 03:06, Peter Alexander wrote:I assume it varies by architecture, but at what size threshold is it faster to copy structs by reference instead of value? If I pass a large struct by value, will dmd optimize it away as a reference?I remember there was a discussion a little while back about how Phobos would assume that structs are cheap to copy, and would simply pass them by value. Is this assumption now "the D way"? Should we all just pass structs by value, assuming cheap copy construction? If so, I think this needs to be documented somewhere (assuming it isn't already), because it's a radical departure from C++, and also from most other languages (where everything is a reference type). People need to be aware of this.What if the byte size of some struct is say a KB or a MB would one still think that copy construction is cheap? In this instance I would not blame poor performance on Phobos but rather than your own design. Cheers Justin
Jan 10 2011
On 10/01/11 03:06, Peter Alexander wrote:I remember there was a discussion a little while back about how Phobos would assume that structs are cheap to copy, and would simply pass them by value. Is this assumption now "the D way"? Should we all just pass structs by value, assuming cheap copy construction? If so, I think this needs to be documented somewhere (assuming it isn't already), because it's a radical departure from C++, and also from most other languages (where everything is a reference type). People need to be aware of this.OTOH maybe I missed your point. Cheers Justin
Jan 10 2011
On Sun, 09 Jan 2011 11:06:22 -0500, Peter Alexander <peter.alexander.au gmail.com> wrote:I remember there was a discussion a little while back about how Phobos would assume that structs are cheap to copy, and would simply pass them by value. Is this assumption now "the D way"? Should we all just pass structs by value, assuming cheap copy construction?The discussion was about assumptions that ranges will make on their elements. Essentially, ranges will expect their element types to be cheaply copied. This does not mean that all structs need be cheaply copyable, nor that ranges cannot be used with expensive-to-copy element types. It just means that for the algorithms defined on ranges, the complexity stated depends on the elements being cheaply copyable.If so, I think this needs to be documented somewhere (assuming it isn't already), because it's a radical departure from C++, and also from most other languages (where everything is a reference type). People need to be aware of this.AFAIK, there has not been a conclusion to this. Once there is, if cheap copy assumption is the result, then I expect documentation to reflect that (probably at top of std.range and std.algorithm). -Steve
Jan 10 2011