Please Scroll Down to See Forums Below
napsgear
genezapharmateuticals
domestic-supply
puritysourcelabs
Research Chemical SciencesUGFREAKeudomestic
napsgeargenezapharmateuticals domestic-supplypuritysourcelabsResearch Chemical SciencesUGFREAKeudomestic

Does Anyone Know Anything About Computer Programming

2

2 ton hoss

Guest
MY NEPHEW ASKED ME THIS QUESTION HE IS VISITING. I DO NOT KNOW THE ANSWER AS I AM NOT A PROGRAMMER, I AM TOO STUPID :D

HE WANTS TO KNOW THE DIFFERENCE BETWEEN "THE STACK" AND "THE HEAP"

THANKS
 
ooh Data Structures, I hated that class.

Here are some vague definitions:

A Heap is a tree where every node has a key that is more extreme (greater or less) than the key of its parent.


Stack:
A collection of items in which only the most recently added item may be removed. The latest added item is at the top. Data extraction method known as "last-in, first-out" or LIFO.

anywho, I hope this helps. (I had to look this stuff up---seems that my hard disk is full and I am also running with too little ram. lol----)

http://www.nist.gov/dads/

Tell him to check the link above for additional definitions
 
best I can remember is that the heap is used for when variables are allocated by the computer randomly. Example. you declare a variable and the computer accesses a part of the heap to store that variable. The stack is a block of space that is allocated by the computer and when a new variable of that type is declared, it only uses that block of space to store the specified variable. Maybe that helped some....its been about 3years since I had a class that dealt specifically with the heap/stack, but im 99% sure thats right ;)
 
I think what he needs to know is how they are handled differently in an OS context. In the most simple terms, staticly allocated variables are stored on the stack, and dynamically allocated variables are stored on the heap.

For instance, if I have a C program that has something like this:

char foo = 'a';

then the OS knows to allocated exactly one byte for the storage of variable "foo" at execution time. This allocation space will be the same every time the program is run, thus it is termed "staticaly allocated".

If I have something like:

if(rand(1) > .5)
MyObj Bar = new Quux;

then the storage for the variable "Bar" will be allocated on the heap, since there's no way the OS can know how much space will be needed. Half of the time, no extra space will be needed, and half of the time, sizeof(Quux) bytes will have to be allocated.

Clear as mud?
 
Top Bottom