How to free memory occupied by C++ routine

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
kirankota79
Premium Member
Premium Member
Posts: 315
Joined: Tue Oct 31, 2006 3:38 pm

How to free memory occupied by C++ routine

Post by kirankota79 »

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?
mahadev.v
Participant
Posts: 111
Joined: Tue May 06, 2008 5:29 am
Location: Bangalore

Post by mahadev.v »

Instead of speculating on the probable cause, posting the exact error message here will help. As far as i know you don't have to handle the memory in a C++ routine explicitly. DataStage does it for you.
"given enough eyeballs, all bugs are shallow" - Eric S. Raymond
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Space allocated to variables local to the routine should be freed. Or you might be able to use static variables.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
OddJob
Participant
Posts: 163
Joined: Tue Feb 28, 2006 5:00 am
Location: Sheffield, UK

Post by OddJob »

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.
Post Reply