MathGroup Archive 2003

[Date Index] [Thread Index] [Author Index]

Search the Archive

Proper way to free memory?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg43576] Proper way to free memory?
  • From: Bob.Buchanan at millersville.edu (Bob Buchanan)
  • Date: Sun, 21 Sep 2003 05:42:16 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Hello,

I've written an external program to be called from Mathematica using
mathlink. Inside one of the C functions I dynamically allocate an
array of integers and another array of doubles. I fill them with data
and then  I pass the results back to Mathematica. The ReturnType of
the function is set to Manual. In the C program I use statements like

  MLPutFunction(stdlink,"List",2)	;
  MLPutIntegerList(stdlink,nn,numneigh)	;
  MLPutRealList(stdlink,dx,numneigh)	;

Since dx and nn are dynamically allocated, before the function returns
I would like to free the space previously allocated. But the following
statements create a segmentation violation at run time.

  free((void *)dx)	;
  free((void *)nn)	;

Am I not supposed to free memory that I'm passing back to Mathematica?
What am I doing wrong?

Thanks,
Bob Buchanan
Bob.Buchanan at millersville.edu


  • Prev by Date: Re: why do recursive function calculations take so long in Mathematica?
  • Next by Date: Re: why do recursive function calculations take so long in Mathematica?
  • Previous by thread: Re: package functions in mathlink
  • Next by thread: Re: Proper way to free memory?