Dear Experts
In our application the values that are sent from FRONT end( Java) are stored in a C++ Structure on Unix box and then a remote procedure call is made .
To store the values that are coming from front end , Im allocating the memory using operator new as below
sys_corresp_struct * p_str_Corresp = (sys_corresp_struct*)new char[sizeof(sys_corresp_struct)];
memset(p_str_Corresp,'\0',sizeof(sys_corresp_struct));
where in sys_corresp_struct is the Structure to hold all the incoming values..
then a function CopyToDcesys_corresp_structcopies the data as below
void CCaslifUtility::CopyToDceSYS_CORRESP_STRUCT(sys_corresp_struct* output,SysCorrespStruct &input)
{
strcpy(char *)output->record_type,(char *)input->recordType.c_str());
strcpy((char *)output->country_code,(char *)input->countryCode.c_str());
strcpy((char *)output->leg_veh,(char *)input->legVeh.c_str());
strcpy((char *)output->boff_code,(char *)input->boffCode.c_str());
strcpy((char *)output->ref_num,(char *)input->refNum.c_str());
strcpy((char *)output->seq_num,(char *)input->seqNum.c_str());
strcpy((char *)output->prod_type,(char *)input->prodType.c_str());
strcpy((char *)output->opn_type,(char *)input->opnType.c_str());
strcpy((char *)output->txn_ccy,(char *)input->txnCcy.c_str());
}
After the data has been copied and the RPC has been made , the memory is released as
delete [] p_str_Corresp;
p_str_Corresp = NULL;
I have been thinking of using an auto_ptr or shared_ptr (from Boost Libraries) instead of using new operator for better memory management.
Can some show me how to allocate a memory to a structure using auto_ptr or shared_ptr ?
Many Thanks