Sequence question



I have a function return a sequence as following:

module Sample {
interface SeqTest {
typedef sequence<double> DoubleSeq;
DoubleSeq get_array(in DoubleSeq seq);
};
};

At servant I implement this as:

static Sample_SeqTest_DoubleSeq *
impl_Sample_SeqTest_get_array(impl_POA_Sample_SeqTest * servant,
const Sample_SeqTest_DoubleSeq * seq,
CORBA_Environment * ev)
{
int i;
Sample_SeqTest_DoubleSeq *retval;

retval = Sample_SeqTest_DoubleSeq__alloc();
retval->_buffer = Sample_SeqTest_DoubleSeq_allocbuf(seq->_length);
retval->_length = seq->_length;
CORBA_sequence_set_release(retval, CORBA_TRUE);

for (i=0; i<seq->_length; ++i) {
retval->_buffer[i] = seq->_buffer[i] * seq->_buffer[i];
}

return retval;
}


At client side, I invoke this function as:

Sample_SeqTest_DoubleSeq *seq_out = NULL;
seq_out = Sample_SeqTest_get_array(obj, seq_in, &ev);


Here is my question:
1) Will Sample_SeqTest_get_array() will allocate memory automatically ?
Or I need to allocate myself for seq_out before invoke the "seq_out =
Sample...." ?

2) Do I need to call
CORBA_free(seq_out); or
CORBA_free(seq_out->_buffer);

to free the allocated memory area.



Thanks
Kuang-Chun Cheng
kccheng@openate.com












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