Re: Proper way to free memory?
- To: mathgroup at smc.vnet.net
- Subject: [mg43607] Re: Proper way to free memory?
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 23 Sep 2003 04:01:57 -0400 (EDT)
- Organization: Universitaet Leipzig
- References: <bkjs7l$hru$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi, since MathLink is always buffered, your segmetation fault has nothing to do with MathLink, When MLPut*List() returns the data are transfered. Regards Jens Bob Buchanan wrote: > > 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