[ale] OT: C not C++ Question

cfowler cfowler at outpostsentinel.com
Sun Dec 29 22:40:15 EST 2002



> 
> 	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.
> 
>

Would it protect the programmer in this case:

String *tmp = String_new("Hello World!\r\r");
tmp = String_new("Hello Again!\r\n");

Since tmp got a new pointer the original pointer is forever
lost.  In Java that memory will just be reaped by GC but in C
it is lost until exit() is called :)

However it does seem that alloca() will help in this instance

Object *obj1 = Object1_new(Object2_new("Nothing"));

Since the prgrammer never really got a poiner to the object created
by Object2_new() above, they can not free it.  This is kinda the 
behavior we are looking to not happen.  We want some good GC.

I guess calling alloca(NULL) is just like doing a System.gc() in Java. 
However alloca() will immediaetly do the GC where Java may or may not at
that particular moment.  Maybe liboop stills needs a GC thread that can
at intervals check ref counts on objects and reap that mem, but it still
does not fix the bad programming as above.



_______________________________________________
Ale mailing list
Ale at ale.org
http://www.ale.org/mailman/listinfo/ale






More information about the Ale mailing list