Home Help Center

Expensive return by value

bambukbambuk Member Alex StovbounOrganization: UBS AGProject: Financial applications
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

  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    You could wrap the sequence in a class:
    sequence<Position> PositionList;
    
    class SharedPositionList
    {
        PostionList list;
    };
    	
    interface ServerOps {
    	SharedPositionList GetPositions();
    };
    
  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    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
  • matthewmatthew NL, CanadaMember Matthew NewhookOrganization: ZeroC, Inc.Project: Internet Communications Engine ✭✭✭
    Note that this topic, and others, were covered in my article "Optimizing Performance of File Transfers " in http://www.zeroc.com/newsletter/issue20.pdf
  • bambukbambuk Member Alex StovbounOrganization: UBS AGProject: Financial applications
    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.
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Instances of classes are passed as smart pointer, so when you copy SharedPositionList, you only increment the reference count. No data is copied.
Sign In or Register to comment.