How far can stack [LIFO] solve do automatic garbage collection and prevent memory leak ?
Nick Keighley
nick_keighley_nospam at hotmail.com
Wed Aug 18 04:39:09 EDT 2010
On 17 Aug, 18:34, Standish P <stnd... at gmail.com> wrote:
> 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 ?
any book of algorithms I'd have thought
http://en.wikipedia.org/wiki/Dynamic_memory_allocation
http://www.flounder.com/inside_storage_allocation.htm
I've no idea how good either of these is
> 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.
I can't make much sense of that. But you seem to see Lisp data
structures in all sorts of strange places. I don't see that Lisp lists
are "nested two column tables"
> we can peek into stacks which is like car.
no.
> if it is not unusually
> costly computation, why not allow it ? there is no need to restrict to
> push and pop.
some stacks have a top() operation.
> 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 ?
I've no idea what you on about
More information about the Python-list
mailing list