Main Page | Report this Page
Computers Forum Index  »  Computer - Object (Corba)  »  [C++ Mapping] using sequence elements of variable...
Page 1 of 1    

[C++ Mapping] using sequence elements of variable...

Author Message
Jesse...
Posted: Wed Oct 22, 2008 10:37 pm
Guest
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.
 
Jon Biggar...
Posted: Thu Oct 23, 2008 6:18 am
Guest
Jesse wrote:
IDL
Quote:

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 at (no spam) floorboard.com
jon at (no spam) biggar.org
jonbiggar at (no spam) gmail.com
 
Jon Biggar...
Posted: Thu Oct 23, 2008 6:18 am
Guest
Jesse wrote:
IDL
Quote:

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 at (no spam) floorboard.com
jon at (no spam) biggar.org
jonbiggar at (no spam) gmail.com
 
 
Page 1 of 1    
All times are GMT
The time now is Fri Nov 27, 2009 11:09 pm