wtf is the point of the heap?

dpopiz

Diamond Member
Jan 28, 2001
4,454
0
0
you know the whole stack vs heap thing in C#? from what I understand, stack is allocated down the physical memory and is popped back up and unallocated as soon as the execution branch finishes. and the heap is the same except it moves up and DOESN'T get gracefully unallocated when the execution branch finishes: it waits around for the garbage collector to find garbage.
 

jgbishop

Senior member
May 29, 2003
521
0
0
I believe it has to do with dynamic memory management. Keeping a stack around is a lot of work (knowing what's on top, what's below, how deep it is, etc.). Here's a nice definition:

Heap Definition
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Stack is a relatively small fixed size, usually set at compile time, while the heap can use the full 2GB per-process address space.

IIRC the stack also can't use virtual memory but that might not be true on modern processors (my first assembly was 6502).
 

oog

Golden Member
Feb 14, 2002
1,721
0
0
a heap is for memory where you don't know how much you need until run-time. the stack generally only contains memory for local variables within functions.