[omniORB] Corba::String_member

Michael Teske subscribe at teskor.de
Thu Nov 6 07:04:11 GMT 2014


Hi,


Am 06.11.14 00:03, schrieb Immanuel Litzroth:
> I'm looking at this code in stringtypes.h
> 
>>inline _CORBA_String_member& operator=(char* s) {
>>   _CORBA_String_helper::dealloc(_ptr);
>>   _ptr = s;
>>    return *this;
>>  }
> 
> I'm a bit confused why it deallocates _ptr.

That's because CORBA string members take ownership of the memory where
the string is stored in, like a _var type. If you assign something from
"char *" the class assumes it has ownership and has to free the memory
on destruction or change.

> I have a struct which is
> initialized with String_members.
> I've got a const char* I want to put into them. 

"_const_ char *" is a different issue. In this case, the string will
have to be be duplicated before taking ownership of the copy, the
orignal will be untouched.

> My only route seems to
> be to create another String_member or String_var and then one of these
> assignment operators?
>   inline _CORBA_String_member& operator=(const _CORBA_String_member& s)
> Or am I missing the correct idiom here?

If you meant to ask if it would be ok to do something like

const char * foo ="bar";
my_string_member = foo;

the answer is yes. No intermediate String_var needed.

Regards,
  Michael

> Regards,
> 
> *Immanuel Litzroth, principal software engineer*
> CloudFounders
> Tel: +32 9 355 34 16
> Support: +32 9 324 25 66
> 
> CloudFounders, Innovators in Cloud Technologies
> <http://www.cloudfounders.com/>
> www.cloudfounders.com
> <http://www.cloudfounders.com/> | www.cloudframesvrun.com
> <http://www.cloudframesvrun.com/>
> 
> 
> 
> _______________________________________________
> omniORB-list mailing list
> omniORB-list at omniorb-support.com
> http://www.omniorb-support.com/mailman/listinfo/omniorb-list
> 




More information about the omniORB-list mailing list