[C++ Mapping] using sequence elements of variable length via _var

This is a discussion on [C++ Mapping] using sequence elements of variable length via _var within the Object forums in Theory and Concepts category; Hi, I am trying to understand the usage of sequences for variable-length elements, and things are in fact rather complex, unclear... and vary from one ORB to the other ! Therefore, I submit the following general questions, for those who are familiar with the C++ mapping mysteries ;-) IDL typedef sequence<T> TSeq; interface Service { TSeq list_Ts(); }; with T as a variable-length type. In my C++ client I get the sequence from the server via: TSeq_var theSeq = server->list_Ts(); 1rst question: which assertions are valid as regards the specification (assume variable i is a CORBA::ULong) ? 1- T_var theT ...

Go Back   Application Development Forum > Theory and Concepts > Object

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 10-22-2008, 01:37 PM
Jesse
Guest
 
Default [C++ Mapping] using sequence elements of variable length via _var

Hi,

I am trying to understand the usage of sequences for variable-length
elements, and things are in fact rather complex, unclear... and vary from
one ORB to the other !

Therefore, I submit the following general questions, for those who are
familiar with the C++ mapping mysteries ;-)


IDL

typedef sequence<T> TSeq;

interface Service {
TSeq list_Ts();
};

with T as a variable-length type.


In my C++ client I get the sequence from the server via:

TSeq_var theSeq = server->list_Ts();


1rst question: which assertions are valid as regards the specification
(assume variable i is a CORBA::ULong) ?

1- T_var theT = theSeq[i];

2- T_var theT;
theT = theSeq[i];

3- T_var theT = (*theSeq)[i];

4- T_var theT;
theT = (*theSeq)[i];


2nd question: Among the valid assertions, what are those where theT takes
memory ownership (thus sharing it with theSeq !), and those where it
performs a deep-copy of the original sequence item ?


Thanks !

JC.


Reply With Quote
  #2  
Old 10-23-2008, 12:44 AM
Jon Biggar
Guest
 
Default Re: [C++ Mapping] using sequence elements of variable length via_var

Jesse wrote:
IDL
>
> typedef sequence<T> TSeq;
>
> interface Service {
> TSeq list_Ts();
> };
>
> with T as a variable-length type.
>
>
> In my C++ client I get the sequence from the server via:
>
> TSeq_var theSeq = server->list_Ts();
>
>
> 1rst question: which assertions are valid as regards the specification
> (assume variable i is a CORBA::ULong) ?
>
> 1- T_var theT = theSeq[i];
>
> 2- T_var theT;
> theT = theSeq[i];
>
> 3- T_var theT = (*theSeq)[i];
>
> 4- T_var theT;
> theT = (*theSeq)[i];
>
>
> 2nd question: Among the valid assertions, what are those where theT takes
> memory ownership (thus sharing it with theSeq !), and those where it
> performs a deep-copy of the original sequence item ?


They should all work and should all invoke a deep copy. However, #3 and
#4 are not recommended--using operator *() on a _var actually invokes
the conversion function operator T*() first. That can lead to
accidental memory management problems.

If you want to avoid the deep copy, just do this:

T &theT = theSeq[i];

but of course you'll have to ensure that you don't access the reference
outside of the lifeime of theSeq.


--
Jon Biggar
jon@floorboard.com
jon@biggar.org
jonbiggar@gmail.com
Reply With Quote
  #3  
Old 10-23-2008, 12:44 AM
Jon Biggar
Guest
 
Default Re: [C++ Mapping] using sequence elements of variable length via_var

Jesse wrote:
IDL
>
> typedef sequence<T> TSeq;
>
> interface Service {
> TSeq list_Ts();
> };
>
> with T as a variable-length type.
>
>
> In my C++ client I get the sequence from the server via:
>
> TSeq_var theSeq = server->list_Ts();
>
>
> 1rst question: which assertions are valid as regards the specification
> (assume variable i is a CORBA::ULong) ?
>
> 1- T_var theT = theSeq[i];
>
> 2- T_var theT;
> theT = theSeq[i];
>
> 3- T_var theT = (*theSeq)[i];
>
> 4- T_var theT;
> theT = (*theSeq)[i];
>
>
> 2nd question: Among the valid assertions, what are those where theT takes
> memory ownership (thus sharing it with theSeq !), and those where it
> performs a deep-copy of the original sequence item ?


They should all work and should all invoke a deep copy. However, #3 and
#4 are not recommended--using operator *() on a _var actually invokes
the conversion function operator T*() first. That can lead to
accidental memory management problems.

If you want to avoid the deep copy, just do this:

T &theT = theSeq[i];

but of course you'll have to ensure that you don't access the reference
outside of the lifeime of theSeq.


--
Jon Biggar
jon@floorboard.com
jon@biggar.org
jonbiggar@gmail.com
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:49 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.