Print

Print


On Mon, Sep 26, 2011 at 3:44 PM, Gary Shannon <[log in to unmask]> wrote:
> On Mon, Sep 26, 2011 at 12:42 PM, Garth Wallace <[log in to unmask]> wrote:
>> The topmost element in
>> turn contains the address of the element below it, that element
>> contains the address of the element below it, and so on.
>
> What you describe is a data structure called a "linked list". A stack
> (normally) resides in consecutive memory locations so it is not
> necessary for each entry to include the address of the next entry.
> That would be redundant. The linked list allows sequential entries to
> be in non-adjacent memory locations. The stack is based on a single
> pointer called the "stack pointer" which normally points to the first
> unused memory location past the top of the stack so that "push"
> consists of "store then increment", and "pop" consists of "decrement
> then retrieve".

IME (and it's been a while since I've had to use any of this), stacks
are frequently implemented as singly linked lists, with the exception
of the run-time stack, which is strictly controlled and assigned its
own segment of memory. Growing data on the heap without limit is just
asking for all sorts of nasty collisions.

But my point is that the idea of a stack requires the idea of memories
residing in fixed addresses. I'm not sure that a term like
"consecutive memory locations" is even meaningful when applied to the
brain.