Stack and Heap Primer

Mar 31

Stack and Heap Primer

Value vs Reference Types in C#: This is an excellent explanation of the programming concepts of the “stack” and the “heap,” and a comparison of value types and reference types. (And, if you’re a C# programmer, and great explanation of how structs are different from full-blown objects.)

The Common Language Runtime allocates memory for objects in two places: the stack and the heap. The stack is a simple first-in last-out memory structure, and is highly efficient. […]

In contrast, the heap can be pictured as a random jumble of objects. Its advantage is that it allows objects to be allocated or deallocated in a random order. As we’ll see later, the heap requires the overhead of a memory manager and garbage collector to keep things in order.

Some good diagrams that cleared up some confusion for me.

(And why don’t I know this already? Because my B.A. is in Political Science. A side-effect of being an “accidental programmer” is that you don’t learn things until you need them, so sometimes you find yourself learning incredibly remedial things later on in your career. Example: I still don’t know the difference between Base 2 and Base 10.)


Comments

by duryodhan,   March 31, 2009 1:53 PM  

Isn't base 2 and bas 10 the same?


by ,   March 31, 2009 3:55 PM  

There are 10 types of people in the world; those that understand binary and those that don't.


by Ross Nelson,   March 31, 2009 6:17 PM  

"Example: I still don’t know the difference between Base 2 and Base 10"

Eight.


by Dave Ward,   March 31, 2009 8:05 PM  

Example: I still don’t know the difference between Base 2 and Base 10

It's not April 1st yet!



Comments are Closed

Thanks to all who participated.

Want to advertise on this site? Contact FM.