| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 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. |
|
#2
| |||
| |||
| 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 |
|
#3
| |||
| |||
| 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 |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.