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:
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?

Comments

  • marc
    marc Florida
    You could wrap the sequence in a class:
    sequence<Position> PositionList;
    
    class SharedPositionList
    {
        PostionList list;
    };
    	
    interface ServerOps {
    	SharedPositionList GetPositions();
    };
    
  • bernard
    bernard Jupiter, FL
    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,
    Bernard
  • matthew
    matthew NL, Canada
    Note that this topic, and others, were covered in my article "Optimizing Performance of File Transfers " in http://www.zeroc.com/newsletter/issue20.pdf
  • marc wrote: »
    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.
  • marc
    marc Florida
    Instances of classes are passed as smart pointer, so when you copy SharedPositionList, you only increment the reference count. No data is copied.