Re: Memory management



Hi,

On Wed, 2002-12-18 at 08:47, Anders Selander wrote:
> Hello,
> 
> is there a way to get the server-side to automatically free data
> structures once they have been passed to the client?
> 
> On the server-side, I am allocating Corba sequences, filling them with
> data, and returning them. Example (simplified):
> 
>   retval = CORBA_sequence_CORBA_octet__alloc();
> 
>   retval->_maximum = size;
>   retval->_length = size;
>   retval->_buffer = CORBA_sequence_CORBA_octet_allocbuf(size);
> 
>   memcpy(retval->_buffer, image, (long)size);
> 
>   free(image);
> 
>   retval->_release = TRUE;
> 
>   return retval;

	This will be freed by the ORB once it has been sent
to the client.

> 
> On the client-side, I am receiving the sequence, using it, and finally
> releasing the object. Example (simlified):
> 
>   client = CORBA_ORB_string_to_object(orb, argv[1], &ev);
> 
>   res = CorbaModule_Interface_Method(client);
> 
>   for (i = res->_length; i > 0; --i)
>           ... res->_buffer[i] ... /* something */

	You're missing a CORBA_free (res). Also note that
you are not allowed to modify the contents of the sequence
returned. To do so you must first copy it.

> 
>   CORBA_Object_release(client, &ev);
> 
>   exit(0);
> 
> Do I need to keep a global reference to the sequence at the server 
> side and write another method that frees the sequence once it is 
> called from the client? Is there no better way, accommodating naive
> clients that cleans up by terminating its process?
> 
> This should be basic stuff. Yet I have failed to find any documention
> on it. Could you give me some pointers to the right places? Or, even
> better, perhaps point out what I have neglected to do?

	Have a look at Table 1-3, "Client Argument Storage Responsibilities" in
the C mapping spec. It should help.

Good Luck,
Mark.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]