[omniORB] Saving memory?

Philip Gilchrist pgilchrist@abingdon.geoquest.slb.com
Tue, 21 Sep 1999 11:23:34 +0100


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.

Philip