[omniORB] How avoid copying "in" parameters?

Wernke zur Borg wernke.zur.borg at vega.de
Thu Feb 7 14:31:29 GMT 2008


> Subject: [omniORB] How avoid copying "in" parameters?
> 
> 
> Hi all,
> 
> When I declare a parameter as "in" inside an IDL,
> it is then implemented as a reference in C++.
> How can I store the parameter/data I receive in this
> reference without copying it?
> 
> For example :
> 
> struct Message
> {
>     attribute string to_do;
> };
> 
> interface Worker
> {
>     boolean addWork( in Message msg );
> };
> 
> ==> implemented as :
> 
> class WorkerImpl : public Worker
> {
>     //..................
>     // I would like to store the msg in a message queue
>     // without copying it because it can generate performance
>     // issues.
>     CORBA::Boolean addWork( const Message& msg )
>   {
>        m_queue.store( msg ); // Store a copy of msg...
>   }
> };
> 
> Any ideas?
> 
> Antonio.



Hi Antonio,

it is not too long ago when I posted the same question to this group. 

I'll quote the answer from Duncan Grisby here:

---------------------------------------------------------------------
On Friday 20 July, "Wernke zur Borg" wrote:

[...]
> The C++ equivalent for this interface is
> 
> // C++
> void DataRelay::putData( const Data& d );
> Data* DataRelay::getData();
> 
> The problem with this is that each data item must be copied at least
> once during putData(). Since performance is an issue in my case I am
> looking for a way to minimise copying the data. However with the const
> argument& I do not see a way to avoid it.

You can't avoid it if you stick with the standard C++ mapping. This is
one of the many issues that makes the C++ mapping far from ideal.

If you're willing to get your hands dirty and make your code omniORB
specific, you can get in at a level below the C++ mapping and avoid the
unnecessary copying. If you look at the code generated by omniidl, in
the SK.cc file, you'll find definitions of call descriptor classes for
each of the IDL operations. Those are the things responsible for
marshalling and unmarshalling arguments, and calling the servant
methods. What you can do is write your own versions of those classes
that do different memory management -- in your case, passing the in
struct argument by pointer instead of const reference.

Then you can override the _dispatch() method of the _impl_ class, which
is the thing responsible for creating the call descriptor and performing
the call.

Hopefully you'll be able to follow the logic through all the generated
code and see how to change it. I wouldn't recommend this path unless
you've definitely established that the data copying is a significant
performance issue, though.

Cheers,

Duncan.

----- end of quote -----

In the end I refrained from making my hands dirty...

Cheers, Wernke



More information about the omniORB-list mailing list