[omniORB] Saving memory?
Sai-Lai Lo
S.Lo@uk.research.att.com
21 Sep 1999 13:38:22 +0100
The CORBA 2.3 C++ mapping has new sequence member functions replace() and
get_buffer() which will do what you want. You can use these functions
starting from omniORB 2.8.0(pre2).
Notice that your code is strictly speaking incorrect. The buffer you
supply to the sequence should come from calling allocbuf() of the
sequence. Using the new operator, while it works in this case is not
always guarantee to work.
Sai-Lai
>>>>> Philip Gilchrist writes:
> Hello:
> There may be another way to do this, here is
> what I do, a problem follows...
> I want to send a large array of data to a
> distributed object without duplicating
> the array merely to send it as a sequence.
> //x is a pointer to a float array:
> float* x = new float[5];
> //the _CORBA_sequence defined in seqtemplates.h
> //allows the following constructor use:
> FloatSequence* y = new FloatSequence(5,5, x);
> This is useful as it allows me to wrap the possibly
> very large array 'x' without allocating more
> memory equal in size to 'x' in the sequence.
> I just have to remember to y->NP_norelease();
> before: delete y; to return ownership of 'x' to me.
> This worked fine. But now I have more complex
> data structures and am using a 'struct' with
> a sequence as a member.
> When the struct is created it gets the no argument
> constructor for the sequence and there is no
> way to get the values of the 'x' array above into
> the struct without copying them there. Which
> will duplicate a large chunck of memory.
> A method that took the arguments of the
> constructor above like:
> y.Set(5,5,x);
> would solve this problem.
> Is there another solution?
> I can modify the _CORBA_sequence template to allow
> this proceedure. I realise that while the sequence
> 'y' has the object 'x' it has owenership and
> can realloc memory etc, but I think if you are
> using the above constructor you know what you are
> doing.
--
Sai-Lai Lo S.Lo@uk.research.att.com
AT&T Laboratories Cambridge WWW: http://www.uk.research.att.com
24a Trumpington Street Tel: +44 1223 343000
Cambridge CB2 1QA Fax: +44 1223 313542
ENGLAND