[omniORB] How is this situation handled - delete non-heap data ?

Rene Jager renej.frog at yucom.be
Fri Nov 14 15:00:33 GMT 2003


On Fri, 2003-11-14 at 13:07, Ali Reza wrote:
> I have a String_var constructed using String_var(char *). As I understand:
> {1} char * (see code below) is allocated as local memory. 

your compiler should warn that it should be "const char * str = "...";

> {2} String_var assumes that the data its pointing too is always on the heap.

yes

> {3} A String_var constructed using char * (mind u not const char *) assumes ownership 
> of the char * used to construct it.
> 
>    char * str = "Blank..."; // not a heap allocation
>      {
>        CORBA::String_var temp1(str);
>        cout << temp1.in();
>      }
> 
> When the String_var temp1 goes out of scope its destructor calls a delete on str - I assume.

correct, assigning a "char *" (non-const!) to a String_var means
"consuming", not "copying"

> But a destructor on str should not be called because it is not allocated on the heap. 

but String_var assumes it's on the heap, so you have to make sure it has
something on heap

> So how is this situation being taken care of ?

assign a "const char *" or use CORBA::string_dup() function

renej

> 
> Cheers
> 
> _______________________________________________
> 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