[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: re: FFI with C and memory deallocation



> Date: Mon, 17 Feb 92 06:00:17 EST
> From: Mark.Perlin@CAD.CS.CMU.EDU
> To: info-mcl@CAMBRIDGE.APPLE.COM
> Subject: re: FFI with C and memory deallocation
> 
> Note:
> 
> Regarding message below, Tara is using MACL 1.3.2, MPW C 2.2, and is running
> under System 6.  Oh, and her thesis concerning an expert system for genetic
> linkage mapping is hanging on this. 

The answer lies within the question: "It seems that the problem might be due 
to memory that is not explicitly de-allocated in the C code."  I assume that
the program is only being called once under MPW, VMS, and Unix, since it
would require special trickery to call main() more than once under those
systems.  The solution is to remember that C does not have garbage collection,
and either deallocate memory when you're done with it, or remember the memory
that you have allocated and use it again when the program is called again.
This is not a Lisp problem, if I correctly understand your description of
what you are doing.


> ------------------------------------------------------------------------
> 
> From: Tara Cox <tara@chimera.hgen.pitt.edu>
> Subject: FFI with C and memory deallocation
> To: info-mcl@cambridge.apple.com
> Date: Fri, 14 Feb 92 17:09:06 EST
> Mailer: Elm [revision: 66.33]
> Status: R
> 
> 
> I have written a lisp program which interfaces with a very large C program
> through the FFI.  The lisp program calls the entry point to the C program 
> with NO arguments.
> 
> The C program works correctly in MPW C as well as compiled on Unix and
> VMS.  If the C program is called once from lisp there usually is not
> problem.  However, when run approx. four or more times from Lisp the
> program will crash the system.  The Lisp program simply calls the C
> program several times... nothing else is being done in Lisp.
> 
> What appears to be happening is that after each call from Lisp the
> memory allocated to the C program is not correctly deallocated.  When
> (room) is used after each run, one can see the _Free_ memory Mac Heap
> decreases to as low as 1K. This does NOT seem to be a problem in MPW C
> or on the other systems.  Ocassionally, the Total amount of memory
> allocated to the Mac Heap also increases.
> 
> It seems that the problem might be due to memory that is not explicitly
> de-allocated in the C code.  The memory allocation module is based on the
> Kernighan and Ritchie's morecore and redefinition of alloc() and free() 
> and, again, doesn't seem to be a problem in MPW C or anywhere else.
> 
> Any suggestions you have would be VERY VERY greatly appreciated.
> 
> Thank you,
> Tara Cox
> 
> University of Pittsburgh
> Department of Human Genetics
> e-mail: tara@chimera.hgen.pitt.edu
> 
> 
>