malloc question

Miller Abel miller.abel at
Thu Feb 26 10:58:42 PST 1998

I'm no Kaffe expert, but I offer this:

gc_malloc() is part of a conservative garbage collector used by the
Kaffe system. It is not a traditional malloc replacement. Curiously, as
with most garbage collection systems, there is no explicit free(). The
free() calls are actually no-ops. The garbage collector is responsible
for marking used memory blocks and sweeping up everything else. It does
this automatically.

If through a linkage problem you managed to get gc_malloc() but the GCC
free(), you will invariably have trouble: gc_malloc will mark its chunks
differently than GCC leading to a problem when an incorrectly linked GCC
free() call gets hold of the pointer.

The premise behind the garbage collector is that gc_malloc() maintains a
list of all allocated chunks and free() does nothing.

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

-- Miller

> ----------
> From: 	e. lambrecht
> Sent: 	Thursday, February 26, 1998 8:48 AM
> To: 	kaffe at
> Subject: 	malloc question
> Hey everybody,
>  I'm trying to integrate some C code (specifically, the ImageMagick
> library) with my Java code that runs under kaffe, but I'm having some
> problems.
> I think it all boils down to dealing with memory allocation. In my
> magickimage.c file that implements the interface to kaffe, the first
> thing I need to do is allocate space for an ImageInfo structure:
>   image_info = malloc(sizeof(image_info));
> now I see that the native.h header file redefines malloc to be
> gc_malloc. This seems ok at first, but later in the code I ask the
> ImageMagick library to free up the memory used by the image_info
> structure:
>   DestroyImageInfo(image_info);
> unfortunately, the whole thing conks out after this. Would this be
> because the DestroyImageInfo function is using the normal free()
> rather than kaffe's gc_free?
> I tried skipping the '#define malloc(A) gc_malloc(A)' so that my code
> would use the normal malloc, and the ImageMagick 'free' call would
> work. My malloc above works fine, but then my code dies a few lines
> later when the ImageMagick library indirectly makes a call to malloc()
> via the fopen() call. According to gdb, the code is dieing at
> chunk_free() in malloc.c:2824.
> I know I haven't given any really good details here - so I guess what
> I'm asking is: what memory allocation considerations do I have to make
> for my .c code to work with kaffe?
> Eric...  
> (p.s. - good work on the compiler. My pure java code works wonderfully
> in it)

More information about the kaffe mailing list