chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] question about garbage collector


From: felix winkelmann
Subject: Re: [Chicken-users] question about garbage collector
Date: Tue, 14 Dec 2004 10:39:41 +0100

On Tue, 14 Dec 2004 07:34:14 +0000, John Lenz <address@hidden> wrote:
> 
> What I am doing here is creating a new symbol table, and then loading into it 
> the type_pointer.
> I create a memory region with C_malloc.  That memory is never freed, but 
> instead it is reused.
> These two functions are the only ones to access this pointer, so reusing 
> memory should not be a
> problem.  I first use space for the pointer, and the way C_intern_in works it 
> does not allocate
> data from a when the symbol is already found, so the memory from the initial 
> call in space will
> not be touched.
> I can't use C_alloc since this function returns control back to some other 
> function.
> 
> 1) Does this interact correctly with the garbage collector?  Since the 
> variables stored in
> space do not have sub-objects, we don't need to recursivly call mark on 
> anything.  Second,
> the memory will not be collected because the pointer will exist thoughout the 
> life of the program.
> This is only around 50 bytes or so, and will only be one of these per module,
> so it isn't really a problem.

If you never store anything that must be kept alive in the symbol, then
this should work. You can build arbitrary structures with proper
headers that look like normal Scheme data, but exist in non-GC'd heap
as long as you don't put references to live Scheme data into those
structures. The collector simply ignores all pointers that point outside
of the GC'd heap.

> 
> 2) Would it be better to use the code commented out there at the end, and use 
> C_heaptop instead
> of allocating data with C_malloc?    My concern with using C_heaptop is 
> actually
> the code there in C_demand and C_rereclaim.  What happens is that the 
> swig_init function looks
> something like this
> 

I think you're right not to use C_heaptop, since the amount of data
needed is bounded and relatively small, doing it the way you do
will be more efficient and predictable.
If I understand correctly, the SetModule call with re-use the symbol, 
but creates a new pointer-object (but with re-used storage for that 
pointer-object), right?


cheers,
felix




reply via email to

[Prev in Thread] Current Thread [Next in Thread]