Discussion:
[omniORB] Fw: (by abcluo@163.com)use sequence<struct> problem ?
roger
2006-10-16 21:52:33 UTC
Permalink
HI!

I am download omniORB-4.0.7-win32-vc7.zip,
I am using omniORB_4.0.7 on Win2000 (MSVC++7.1) platforms,
and the echo examples work fine .
Now I use data sequence,but have the problem :

//----------IDL---------
struct NetDataItem
{
long id;
string name;
};
typedef sequence<NetDataItem> DataArray;
typedef sequence<long> DataLongArray;
interface QDataSeq
{
DataArray QueryDatas();
DataLongArray QueryLongData();
};

//---------server code--------------
// return struct data Sequence
DataArray* QDataSeq_i::QueryDatas(){
int cnt =100;
DataArray_var datas = new DataArray((CORBA::Long)cnt);
datas->length(cnt);
for (int i =0;i< cnt; ++i)
{
datas[i].id = (CORBA::Long)(i+1);
datas[i].name = CORBA::string_dup("aaaa"); // is OK??
}
std::cout << "OK" << endl;
return datas._retn();
}
// return long Sequence
DataArray* QDataSeq_i::QueryLongData(){
int cnt =100;
DataLongArray_var datas = new DataLongArray((CORBA::Long)cnt);
datas->length(cnt);
for (int i =0;i< cnt; ++i)
{
datas[i] = (CORBA::Long)(i+1);
}
std::cout << "OK" << endl;
return datas._retn();
}

//-----------client code-----------------------
this arises some exception of free sequence. why?
//query struct data Sequence , use _var
void queryData(QDataSeq_ptr e)
{
DataArray_var dest = e->QuearyDatas();
int len = pdest->length();
std::cerr << "query sequence size £º" << len << endl;
//do something
}
/* use delete sequence ptr
void queryData(QDataSeq_ptr e)
{
DataArray* pdest = e->QuearyDatas();
int len = pdest->length();
std::cerr << "query sequence size £º" << len << endl;
//pdest->release();
delete pdest; // arise some exception.
//If this isn't used 'delete' , it have memory leak,but run OK.
}
*/

//query long Sequence. It is work fine and not have memory leak.
void queryData(QDataSeq_ptr e)
{
DataArray_var dest = e->QuearyDatas();
int len = pdest->length();
std::cerr << "query sequence size £º" << len << endl;
//do something
}
====================================
Get a list of NetDataItem and display it, ERROR IN THE CLIENT.
but Get a list of long ,it work fine.
why?
Help me!
How to fine use sequence of struct in the client and server?

2006-10-16 roger007



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.omniorb-support.com/pipermail/omniorb-list/attachments/20061016/b6327e0b/attachment.htm
Clarke Brunt
2006-10-16 22:49:17 UTC
Permalink
...
...
After looking briefly, I can't see anything wrong with the code.

Is there any possibility that you are mixing up debug/release builds of
your own code and omniORB. Or other different versions of the run time
library. With VC6, you had to choose Debug (or Release) Multi-threaded
DLL is the version in order to match the one that omniORB was linked
with.

If the run time library doesn't match, then you can get problems where
omniORB has allocated memory using one version of the heap, and your
code tries to delete the memory using a different version.

This doesn't fully explain why it might work with longs but not with
structures though.
--
Clarke Brunt, Principal Software Engineer, Trafficmaster


This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the system manager. This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
Loading...