Archived
This forum has been archived. Please start a new discussion on GitHub.
Expensive return by value
I have a server-side method that returns a sequence to the client:
The C++ abstract class produced by slice2cpp dictates that GetPosition() returned vector<Position> by value which is expensive for bigger vectors.
Is it possible to return a smart pointer instead? If not, what other solutions exist?
sequence<Position> PositionList; interface ServerOps { PositionList GetPositions(); };
The C++ abstract class produced by slice2cpp dictates that GetPosition() returned vector<Position> by value which is expensive for bigger vectors.
Is it possible to return a smart pointer instead? If not, what other solutions exist?
0
Comments
-
You could wrap the sequence in a class:
sequence<Position> PositionList; class SharedPositionList { PostionList list; }; interface ServerOps { SharedPositionList GetPositions(); };
0 -
If you can take advantage of "named return value optimization" (NRVO), this return copy will be optimized out.
If you can't, you could use AMD (asynchronous method dispatch) in your server for this operation. The "return" parameter becomes an "in" parameter on the AMD callback.
Best regards,
Bernard0 -
Note that this topic, and others, were covered in my article "Optimizing Performance of File Transfers " in http://www.zeroc.com/newsletter/issue20.pdf0
-
You could wrap the sequence in a class:
sequence<Position> PositionList; class SharedPositionList { PostionList list; }; interface ServerOps { SharedPositionList GetPositions(); };
How does this help? A copy of the SharedPositionList will be returned which will contain a COPY of PositionList.0 -
Instances of classes are passed as smart pointer, so when you copy SharedPositionList, you only increment the reference count. No data is copied.0