Whats difference between stack and heap in C#?

  • Thread starter Thread starter COHENMARVIN
  • Start date Start date
C

COHENMARVIN

I'm reading that the stack is where 'value' types are created, and the
heap is where reference objects are allocated but I'm wondering if
these are just 2 arbitrary sections of memory, or there is more to it.
Also on a somewhat related topic, in C++ I've read that a DLL is in a
separate section of memory with its own variables. Is this true also
in C#? If you have 10 assemblies all calling the same DLL, where are
the 10 copies of the DLL variables kept? And what is the relationship
between DLL and assemblies? Is a DLL just a module in an assembly?
Thanks,
Marvin
 
I'm reading that the stack is where 'value' types are created, and the
heap is where reference objects are allocated but I'm wondering if
these are just 2 arbitrary sections of memory, or there is more to it.

Well, there's slightly more to it - and there's certainly more to it
than "value types go on the stack" but broadly speaking you only need
to worry about stack vs heap.

It can be argued (http://csharpindepth.com/ViewNote.aspx?NoteID=41)
that you shouldn't care even that far. That sounds okay until your
stack overflows :)
Also on a somewhat related topic, in C++ I've read that a DLL is in a
separate section of memory with its own variables. Is this true also
in C#? If you have 10 assemblies all calling the same DLL, where are
the 10 copies of the DLL variables kept? And what is the relationship
between DLL and assemblies? Is a DLL just a module in an assembly?

There aren't 10 different copies - there'll just be the one, assuming
you've only got a single AppDomain.

A DLL is usually a whole assembly, not just a module.

Jon
 
Back
Top