I am using a c++ routine in the parallel jobs and some tables are huge and this routine is applied on every row of the column. It returns char*. After running some jobs , the next jobs are just getting aborted. I am doing force compile 3 to 4 times and then only the job is running. I don't know if this is due the memory occupied by the routine.
In future i want to use all these jobs to be used in a sequence and i don't want to go into all these problem of aborting.
Any suggestions please?
How to free memory occupied by C++ routine
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 315
- Joined: Tue Oct 31, 2006 3:38 pm
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
The problem is that you never get the opportunity to free the memory that you have allocated for a returned string.
I have tried the following type of code:
static char * pszReturnString = 0 ;
\\ For a 256 char return type
if ( pszReturnString == 0 ) pszReturnString=new char[256] ;
\\ Code...
return pszReturnString ;
This method has been advised in other posts on this forum.
The static allows the return string to persist, but in theory will always leave the one allocation of pszReturnString. I suspect though this will get freed when the related process finishes.
Alternatively you could just use:
static char szReturnString[256] ;
This auto variable is possibly a bit more friendly to memory garbage collection.
I have tried the following type of code:
static char * pszReturnString = 0 ;
\\ For a 256 char return type
if ( pszReturnString == 0 ) pszReturnString=new char[256] ;
\\ Code...
return pszReturnString ;
This method has been advised in other posts on this forum.
The static allows the return string to persist, but in theory will always leave the one allocation of pszReturnString. I suspect though this will get freed when the related process finishes.
Alternatively you could just use:
static char szReturnString[256] ;
This auto variable is possibly a bit more friendly to memory garbage collection.