[omniORB] sequence mapping in C++
Thierry DESCOMBES
descombt at ipnl.in2p3.fr
Tue Mar 2 09:48:15 GMT 2004
Hi,
I need help for using a mapped sequence in C++. Here is the IDL type
declaration:
typedef unsigned short Adc;
typedef octet Canal;
typedef long TimeCpt; // Signé pour que le tri soit + facile !
struct AdcData
{
Adc adcValue;
Canal canalValue;
};
typedef sequence<boolean> SeqHitData;
typedef sequence<AdcData> SeqAdcData;
struct AdcEventData
{
TimeCpt cptTimeValue;
SeqAdcData adcs;
SeqHitData hits;
};
typedef sequence<AdcEventData> SeqAdcEventData;
I'd like the sequence to be initialized by a function... but the following
code causes memory leak:
void main()
{
...
SeqAdcEventData *seq=readData();
...
}
//----- I'm trying to do something like that:
SeqAdcEventData *readData()
{
SeqAdcEventData *seq=new SeqAdcEventData(1000);
AdcEventData currentAdcEventData;
for (int i=0; i<rand()%1500; i++)
{
currentAdcEventData.adcs.length(64);
// to be less complicated:
currentAdcEventData.hits.length(0);
currentAdcEventData.cptTimeValue=rand()%10000;
for (int j=0; j<rand()%64; j++)
{
AdcData adcDatas;
adcDatas.adcValue=rand()%1024;
adcDatas.canalValue=rand()%64;
currentAdcEventData.adcs[j]=adcDatas;
}
(*seq)[i]=currentAdcEventData;
}
return seq;
}
What is the correct way to do that ? In the book "advanced CORBA
Programming with C++", I can read "Never pass a sequence to a function for
modification if the release flag is false". So in my case, how must I do to
have the flag set to true? Pleeeaasse Hellp !!!!
Thanks a lot in advance.
Cheers,
Thierry
More information about the omniORB-list
mailing list