Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

STACKS

Name: Anonymous 2010-06-04 17:52

STACKS ARE THE CANCER KILLING PROGRAMMING, SAGE IF YOU AGREE

Name: Anonymous 2010-06-04 18:50

What I want to know is where this textbook meme came from that represents stacks as a stack of plates on a spring. The spring is completely superfluous to the image and such a bizarre thing to add, but every introductory text on stacks seems to have it.
I wonder who started that.

Name: Anonymous 2010-06-04 18:57

>>2
Otherwise the plates won't be popped off very easily

Name: Anonymous 2010-06-04 18:58

>>3
They'd be popped off a lot more easily, because the pile wouldn't be moving as you were removing the plate.

Name: Anonymous 2010-06-04 19:01

You always have access to the top plate with a spring mechanism that retreats downwards into the floor. Without the spring, large numbers of plates would require a stepladder.

Name: Anonymous 2010-06-04 19:03

>>4
Think about it this way. When you pop something off a computer stack, when you pop again, you don't have to find the first plate, you just pop, because the stack pointer has been updated. This is the spring. Otherwise you would have to reach down into the box to find the plate

Name: Anonymous 2010-06-04 19:39

>>5
With a spring your stack is limited to the size of the spring, which in practice is almost certainly smaller than the amount of plates you can reach without a stepladder.

>>6
You don't need to find the plate without the spring either: it's the one on top.

I realize you guys have accepted the spring element without ever questioning it, but these are just empty rationalizations. It's completely superfluous.

Name: Anonymous 2010-06-05 0:36

The stack is loaded in the top of memory and grows downwards. Popping something off the "top" of the stack is removing the bottom-most "plate". Furthermore the spring analogy implies the top of the stack is stationary and the rest of the stack moves in relation to it; This is incorrect. Your spring analogy fails. Better to just pretend the entire stack mechanism is a black box that holds your data, you blissfully ignorant twats.

Name: Anonymous 2010-06-05 1:28

Who the fuck cares about springs? The analogy is used because buffet plate stacks do their best to show only the top plate and not the whole stack as it descends into the tabletop. This is to help students understand that you're only dealing with the top of the stack at any time since the other end is in the table.

Name: Anonymous 2010-06-05 1:43

a stack is a Pez dispenser, except of Pez it dispenses delicious buffer overflows.

Name: Anonymous 2010-06-05 4:28

>>7
With a spring your stack is limited to the size of the spring
Your stack is also limited in programming languages. So the analogy works?

I do agree with you though, the spring is totally superfluous and could lead to confusion. It should not be used. I have *never* actually heard this analogy before; I've always just thought of it as a regular stack of plates, or a deck of cards, or something like that.

Name: Anonymous 2010-06-05 6:59

>>7
No no, in >>5 the spring's base is a negligibly large distance away, embedded somewhere near the centre of the planet. Its Young modulus is such that it compresses by exactly one plate when you push.

Name: Anonymous 2010-06-05 7:19

>>7
>>6-kun here again. What you don't realize is that if the plates are in a spinged box.  The top of the stack is the top of the box. Without the spring, there is no plate in position 1.

Name: Anonymous 2010-06-05 7:59

EXPERT STACK DISCUSSION

Name: Anonymous 2010-06-05 9:53

>>2
I've seen that analogy in use, but the implementation of the "spring" was either limited or nonexistent.  I think they just said "in real life, the top plate on the dispenser remains accessible because a spring supports the stack of plates from a suitable height" and then "The computer does not require a spring because, no matter how long its stack grows, the top-most layer is always easily accessible."

>>7
That's because computer stacks have been implemented much more efficiently than plate stacks.  They never implemented anything better than O(n) plate stacking algorithms and most enterprise dining facilities tolerate O(n^2).

>>8
Your explanation makes no sense.  A "stack" has only one side and that's the side that accepts things and from which things are popped off.  It doesn't matter if it's the "top" or "bottom" as long as it is the same side.

Name: Anonymous 2010-06-05 10:53

i disagree

Name: Anonymous 2010-06-05 18:34

>>15 is the reason why books resort to the dinner plate explanation.

Learn assembly language. The stack is completely accessible in it's entirety, from the first item you push onto it until the 2000,000th item, at any time. The only reason higher level languages don't grant you access to modify those other stack locations is because people like you need training wheels. This is because you're incapable of understanding the actual logical layout of the stack. Like I said earlier, it's better for you (you specifically) to imagine the stack as a black box, like you did with your truly profound "hurp derp one side"   conceptually constipated turd-blossom.

Name: Anonymous 2010-06-05 18:36

Name: Anonymous 2010-06-05 19:28

>>17
You don't seem to understand the concept of understanding concepts.

Name: Anonymous 2010-06-05 19:43

>>17
No need to freak out, man.

Name: Anonymous 2010-06-05 20:11

What I want to know is where this textbook meme came from that makes analogies between abstract data types as concrete objects.  The application is completely extraneous to the abstraction and such an unecessary thing to add, but every introductory text on abstract data types seems to have it.
I wonder who started that.

Name: Anonymous 2010-06-05 20:42

>>21
You should wonder more things, like where the name 'stack' comes from.

Name: Anonymous 2010-06-05 20:47

mad stackz

Name: 1-21 2010-06-05 20:51

>>17
A stack can be implemented in any way internally, but it's usually considered a data structure which can do 2 operations:
Push object into stack
Pop object from stack
Check if stack is empty
(Optional)Peek at the top of the stack.
(Optional)Get total item count.

Pushing/popping/checking for empty/peeking should be O(1).
Aritrary access or length may or may not be implemented, and the time-space needed is unspecified.

How the stack is internally represented is usually irrelevant. Here's a few possible implementations:
1) Fixed size array which cannot grow. Items are either added from low indexes to high indexes, or from high to low. It doesn't really matter how it's done. Such approach can let you access any element in the stack at O(1).

2) Same as 1, but the implementation may re-allocate it to grow it.

3) Linked list or doubly linked list. This is rather common when using Lisp. (cons/push is push, car is peek, cdr/pop is pop, length is length, null is empty check) Arbitrary element access and length are O(n).

4) The assembly stack is a convention which usually operates by having some push/pop instructions which operate on the data in the proximity(-4,0,4(sizeof(int)) of esp (stack pointer). The operating system usually sets up a stack segment and sets the stack pointer register to it (at its end), push instruction places a value at [esp-4] and subtracts 4 from esp, pop takes the value from [esp] and writes it where it needs to be written (argument) and increments esp by 4. The stack pointer can be operated directly on, as well as any stack memory (just like any memory). Functions usually set up stack frames for local variables in the function prologue, and clean up the stack frame in the function epilogue. During a functions execution, register values that need to be saved may be staved on the stack and popped when they're needed, or accessed directly on the stack. Doing a function call will push the address of where to return (after the call) on the stack and jump to the function address. A return instruction would pop a value from the stack into the instruction pointer, thus returning to before the function call. Accessing local variables or arguments is done by looking them in the stack directly (you usually have a base stack pointer register which is set at the beginning of the function allowing you to index appropriately, but such a stack pointer is not absolutely needed and a compiler (or human) can just address the stack directly through relative offsets into the current stack pointer. Having a base pointer just helps in keeping such offsets fixed as opposed to varying (the stack pointer usually varies)).

These are intended usages, but nothing says you can't use the instructions for their behaviour if you need to. The OS may grow the stack if it reaches its limits. This is usually done by reserving the area under the stack and setting special page protection bits that would cause the OS (usermode or kernel mode) to allocate a few more stack pages under the current stack. This can continue until a certain amount has been hit, and once it hits that, a stack overflow exception would be signaled. (I mostly described x86 / Win32 stack here, but it's true for a variety of architectures, with some differences).

The CPU stack is more specialized as you can see, and while you can use it as a normal stack as well, it's usually used for doing interprocedural control-flow, accessing arguments and local variables. I've used the CPU stack as a normal data structure on a few ocasions, but I do consider such use to be abuse(incorrect use can and will cause crashes and if you're setting esp to your memory, you won't be able to access the normal callstack until you're done), altough not of the 'very wrong' kind.

Name: Anonymous 2010-06-05 21:13

>>24
I've used the CPU stack as a normal data structure on a few occasions
Damn, now you got me interested.

Name: Anonymous 2010-06-05 21:28

>>17
Considering you used the phrase "hurp derp" I have no prospects of being enlightened of correct or incorrect information by your posts and henceforth any post I attribute to being of your posting will be ignored as trolling.  Furthermore, I do not take kindly to your belittling attitude.

Name: Anonymous 2010-06-05 23:10

>>26
you said hurp durp, your argument is invalid.

Name: Anonymous 2010-06-05 23:17

>>27
But his second "u" was actually an "e."

Name: Anonymous 2010-06-06 1:49

>>27
you said ``your argument is invalid'', your argument is invalid.

Name: Anonymous 2010-06-06 2:11

>>29
*you're

Name: Anonymous 2010-06-06 2:29

>>30
What about my being a  ?

Name: Anonymous 2010-06-06 3:44

>>9
This is to help students understand that you're only dealing with the top of the stack at any time since the other end is in the table.

mov     eax, dword [esp + 4]
OH SHIT

Name: Anonymous 2010-06-06 3:51

>>32
unshift     @a, 5;
unshift     @a, 7;
print       $a[1];

back to kindergarten, please

Name: Anonymous 2010-06-06 13:22

reminds me that I wanted to roll my own Forth sometime

but then only good tutorial I have for it uses the shittiest assembler known to man

Name: Anonymous 2010-06-06 13:27

>>34
Forth isn't difficult. Just read a normal forth book and you'll be able to work out a basic one. Either that or just translate it to a better assembler.

Name: Anonymous 2010-11-15 0:45

Name: Anonymous 2010-12-17 1:30

Xarn is a bad boyfriend

Don't change these.
Name: Email:
Entire Thread Thread List