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

Standish P stndshp at gmail.com
Tue Aug 17 13:34:04 EDT 2010


On Aug 16, 11:09 am, Elizabeth D Rather <erat... at forth.com> wrote:
> On 8/15/10 10:33 PM, Standish P wrote:

>
> >>> 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.
>
> Forth uses two stacks.  The "data stack" is used for passing parameters
> between subroutines ("words") and is completely under the control of the
> programmer.  Words expect parameters on this stack; they remove them,
> and leave only explicit results.  The "return stack" is used primarily
> for return addresses when words are called, although it is also
> available for auxiliary uses under guidelines which respect the primary
> use for return addresses.
>
> Although implementations vary, in most Forths stacks grow from a fixed
> point (one for each stack) into otherwise-unused memory.  The space
> involved is allocated when the program is launched, and is not managed
> as a heap and allocated or deallocated by any complicated mechanism.  On
> multitasking Forth systems, each task has its own stacks.  Where
> floating point is implemented (Forth's native arithmetic is
> integer-based), there is usually a separate stack for floats, to take
> advantage of hardware FP stacks.
>
> >>     - is forth a general purpose language? Yes
> >>     - are all algorithms stack based? No
>
> > Does Forth uses stack for all algorithms ? Does it use pointers , ie
> > indirect addressing ? If it can/must use stack then every algorithm
> > could be made stack based.
>
> Forth uses its data stack for parameter passing and storage of temporary
> values.  It is also possible to define variables, strings, and arrays in
> memory, in which case their addresses may be passed on the data stack.
>
> Forth is architecturally very simple.  Memory allocations for variables,
> etc., are normally static, although some implementations include
> facilities for heaps as needed by applications.

> although some implementations include facilities for heaps as needed by applications.

How are these heaps being implemented ? Is there some illustrative
code or a book showing how to implement these heaps in C for example ?

Are dictionaries of forth and postscript themselves stacks if we
consider them as nested two column tables which lisp's lists are in
essence, but only single row. Multiple rows would just be multiple
instances of it at the same level inside parens.

we can peek into stacks which is like car. if it is not unusually
costly computation, why not allow it ? there is no need to restrict to
push and pop.

roll( stack_name, num)

itself can give all those postfix permutations that push and pop cant
generate with a single stack. Can we use dictionaries to generate
multiple stacks inside one global stack ?




More information about the Python-list mailing list