[ale] OT: C not C++ Question
Danny Cox
danscox at mindspring.com
Sun Dec 29 17:57:38 EST 2002
On Sat, 2002-12-28 at 23:20, cfowler wrote:
> I've been working on a little project to replicate the success I've had
> in Java (fast programming) to C (slow programming). I've been
> replicating the Java classes to C and not C++. But I've come into an
> interesting issue where since we have no garbage collector in C that we
> must be extremely careful to free all allocated data. All the code in
> 'liboop' malloc()'s each object.
You might look into Henry Spencer's alloca() implementation that uses
malloc. The gcc alloca() allocs mem from the stack, which is reclaimed
automatically when the function returns from the function that uses it.
Henry's alloca() uses malloc, but keeps the blocks in a linked list.
Calling alloca(0) in the "top loop" of your program performs garbage
collection.
This technique is sneaky, underhanded,
not-that-for-which-it-was-intended, and a kludge, but it'll work.
Just how maintainable the code will be is up to you.
I'll go back to lurking, now ;-)
--
kernel, n.: A part of an operating system that preserves the
medieval traditions of sorcery and black art.
Danny
_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list