Felix currently has some memory management issues: the collector
can't run except at the top level, and the gc system itself needs
to co-exist with C/C++ so it isn't a highly tuned dedicated collector.

The one saving grace of the system is that it can *delegate* 
memory management to C++ where appropriate. For example,
the Felix collector knows nothing about the char array used
by the standard string class: that is managed by C++ using
constructors, assignment ops, and destructors.

Now, there are some circumstance where gc is clearly a BAD
idea. Here is one:

        map f (map g ls)

In this code, map f is the only function that can 'see'
the result of map g ls, so if we know map f doesn't hang
on to that list, we can delete it. map f can't itself
determine that by itself, because it doesn't know its
argument is a temporary (only whether it keeps hold
of the argument). but the compiler knows map g ls
can only be 'reached' by map f exporting a dependency,
so together, we might figure out that it is safe to
delete the temporary.

In fact, if map f returns a list of integers, it is always
safe, since that precludes exporting.

*********************************************

Another idea is to provide reference counting.
I am thinking of using a Judy array, so that
the counter are localised, and can be examined
without looking near the object.

The scheme is something like: ref counted pointers
are collected in the usual way by the gc, except that
if the ref-count is zero, they can be reaped earlier,
and, in particular, inside *functional* code.

A ref counted type is NOT the same as the original.
For example 

        counted[int]

is actually a pointer to a ref counted int on the heap.
HOWEVER, counted pointers can navigate and can be interior.
That is, you can have pointers INTO an array or struct
(because Judy will find the containing heap object for you).

The implementation is just the usual C++ ref counting pointer,
except for one problem: the constructors and destructors etc
need a pointer to the gc (since the gc owns the judy array
containing the counts). That means we actually have to
use functions like:

        copy(gc, src, dst);
        assign(gc, src,dst);

which are also type specific .. these just do the counting
the same way for all objects .. then invoke the C++ ctors/dtors
assign ops, etc.

Hmmm ...



-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to