View mode: basic / threaded / horizontal-split · Log in · Help
July 12, 2010
Cost of Returning Unused Struct?
I know that large structs are generally returned from functions by the caller
passing in a hidden pointer.  Assuming the function is not inlined, is this
cost mitigated in any way if the return value is not used?  In other words, if
the return value is not used, then is returning a large struct from a function
still costly?

The use case for this is having the put() methods of structs that allow put()
to be called with the type of the struct return this.  This would allow
reductions like reduce!"a.put(b)" to be performed.  For example:

struct LargeStruct {
   LargeStruct put(LargeStruct rhs) {
       // Do stuff.
       return this;
   }
}

LargeStruct[] arr = getLargeStructs();
auto combined = reduce!"a.put(b)"(arr);
Top | Discussion index | About this forum | D home