View Single Post
  #2   Report Post  
Posted to comp.lang.visual.basic,microsoft.public.excel.programming
Bob Kilmer Bob Kilmer is offline
external usenet poster
 
Posts: 280
Default When to use a stack?

Andrew,
I haven't done a lot of stack implementation, but my general understanding
is that one use of a stack is for storing procedure variables and memory
locations while processors call other procedures. All of the current
procedure variables get stuffed onto the stack to reserve their value, along
with the memory location to resume from, and the process continues execution
at the new memory location implied by the call. The new procedure may itself
call another procedure and store its info on the same stack, and so on.
Eventually the last procedure completes, returns control to the calling
procedure which pops its variables from the stack, eventually completes,
returns control, pops variables, etc. At least that is the myth I carry
around in my head. There are other uses for stacks, as in parsing streams of
input. I am sure you can find more academic explanations.

I can envision using a VB Collection for a stack, which, as a practical
matter, would store VB objects in an order that could be controlled with
indexes. I write a lot of business and engineering software and I do not
remember implementing something I would really call a stack. Linked lists,
b-trees, arrays, other data structures, some may have been used like a stack
on a small scale. A stack is a pretty low level data type not often
encountered as such in modern business programming where the goal often is
patching together encapsulated data types (objects), data streams and whole
applications using higher level languages.

My $0.02,
Bob

"Andrew" wrote in message
om...
Last night I was reading about implementing my own stack. The example
given pushes items on and off the stack at the start and end of each
procedure (ie. in a std module). What's not so clear is how this
would work with class objects. In this case do you have to push the
object on the stack at the start of every public procedure etc. in the
class and pop it off at the end? I can't see how else you can know
which object is active - or is this not normally a situation where a
stack is employed?

Thanks in advance,
Andrew