malloc question
Thu, 26 Feb 1998 12:27:31 -0700 (MST)

> Others watching this list will have to comment on whether there is a way
> to explicitly release a gc_malloc'ed chunk without waiting for garbage
> collection.

There are a pair of calls gc_malloc_fixed() and gc_free_fixed() that
should do what you want.

Here are some notes on the GC I made up when an earlier GC question
came up... I don't think I cc'd the list though.

As to the original poster's questions, I suggest setting things up so
that your Java objects associated with ImageMagick objects contain
pointer to the image data, then you can just rely on the garbage
collector and can simply get rid of all free()'s.  For the I/O related
allocations, you should re-direct those operations through the
threaded IO calls anyway ---see kaffe/kaffevm/threadCalls.h.

I hope this helps,



I've been messing with the GC a bit recently, and have these notes on
how I think it works...  Warning: I may be getting some of this wrong,
so when in doubt, check with the source....

>         gc_malloc
>         gc_free

These are the standard allocation functions.  The second argument to
gc_malloc is a pointer describing how the GC system should deal with
the allocation.

>         gc_malloc_fixed
>         gc_realloc_fixed

These are just calls to gc_malloc() with the second argument being 
&gcFixed.  gcFixed effectively tells the GC that these objects should
never be released by the GC (e.g., they are root objects).  It also
doesn't *walk* the objects, so any pointers in a &gcFixed block will
go unnoticed by the GC.  (Use &gcRoot for a root object that gets
walked.  See the various definitions at the top of gc-incremental.c)

>         gc_attach
>         gc_reattach

gc_attach is used to attach a statically allocated chunk of memory to
the GC system.  Now, you obvious cannot free such an object, but you
do want to walk them to extract any pointers to other objects.  I
don't think gc_reattach is actually used anywhere...

>         gc_heap_malloc
>         gc_heap_free

gc_heap_malloc() is used to implement gc_malloc().  It actually finds
a region of memory to satisfy a request.  (The GC system uses pages of
like-sized objects.  gc_heap_malloc looks for a page with a free,
appropriately sized object in it, or it allocates such a page if none
are available.)  gc_heap_free does just the opposite.

>         gc_heap_isobject

This tells you if a given pointer actually points to a GC object.

If you want to allocate something that isn't collected (and isn't
walked) use gc_malloc_fixed().  If you want to allocate something that
is never collected, but does get walked, use gc_malloc(size, &gcRoot);