[Q] How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?

Standish P stndshp at gmail.com
Mon Aug 16 03:20:17 EDT 2010


[Q] How far can stack [LIFO] solve do automatic garbage collection and
prevent memory leak ?

Because a stack has push and pop, it is able to release and allocate
memory. We envisage an exogenous stack which has malloc() associated
with a push and free() associated with a pop.

The algorithm using the stack would have to be "perfect" to prevent
stack overflow or condition of infinite recursion depth. This would
involve data type checking to filter out invalid input. The task must
be casted in an algorithm that uses the stack. Then the algorithm must
be shown to be heuristically or by its metaphor, to be correct using
informal reasoning.

Are there any standard textbooks or papers that show stacks
implemented in C/C++/Python/Forth with malloc/free in push and pop ?
If Forth is a general processing language based on stack, is it
possible to convert any and all algorithms to stack based ones and
thus avoid memory leaks since a pop automatically releases memory when
free is an intrinsic part of it.

K&R ANSI has the example of modular programming showing how to
implement a stack but he uses a fixed length array. It is also
possibly an endogenous stack. We look for an exogenous stack so that
element size can vary.

=======
Standish P <stndshp at gmail.com>



More information about the Python-list mailing list