Re: Stack vs. Heap Question, Please Help
- From: Jon Skeet [C# MVP] <skeet@xxxxxxxxx>
- Date: Fri, 31 Mar 2006 07:24:19 +0100
Nick Hounsome <nh002@xxxxxxxxxxxxxxxxxx> wrote:
I don't know - I think that the idea of variables being on the stack or
on the heap (along with the concept of stack frames) is very important
when it comes to understanding threading, and why if two threads are
running the same method at the same time (or even a single thread
running a method recursively) they get separate local variables, but if
they access the same object on the heap, that data is shared.
struct parameters and structs within methods are thread local as
(recursively) are any structs they contain directly. Everything else is
shared. You don't need to use the words stack or heap to explain this.
You don't *need* to, but it helps IMO.
(Things get a lot more complicated with anonymous methods, by the way -
variables which look local can end up being captured, and then at
different levels. All kinds of weird stuff can happen.)
P.S. It is totally possible to implement a stack in a stackless
architecture - just pass a pointer to the array of arguments and allocate
frames off the heap - of course you then have a "stack" but it is a
different sort of stack and not as efficient for aloocation although the
deallocation efficiency still applies.
Sure.
--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.
- References:
- Stack vs. Heap Question, Please Help
- From: arcticool@xxxxxxxxxxx
- Re: Stack vs. Heap Question, Please Help
- From: Larry Lard
- Re: Stack vs. Heap Question, Please Help
- From: Nick Hounsome
- Re: Stack vs. Heap Question, Please Help
- From: Jon Skeet [C# MVP]
- Re: Stack vs. Heap Question, Please Help
- From: Nick Hounsome
- Stack vs. Heap Question, Please Help
- Prev by Date: Re: is it possible?
- Next by Date: Sending Email through Exchange
- Previous by thread: Re: Stack vs. Heap Question, Please Help
- Next by thread: Re: Stack vs. Heap Question, Please Help
- Index(es):
Relevant Pages
|