n!,
Not quite true. The managed heap also uses a pointer to indicate were
the next object should be placed in the heap. Once the object has been
inserted into the heap, the pointer is moved to point after the last object.
However there is another layer of indirection since you will have to go from
stack -> heap before you get the correct object. Also the stack is local for
each thread and is inherintly thread safe, where as the heap is free-for-all
memory (of course for each application) so I would (wouldn't swear my
life on it - perhaps someone can confirm) think there is some kind of
lock mechanism being used to ensure thread safety of the information used
in the heap.
//Andreas
"n!" <nf********@nomailplease.com> skrev i meddelandet
news:O5**************@TK2MSFTNGP09.phx.gbl...
why value types which are stored in the stack, give better performance,
than reference types which are stored in the heap?
are not both stored in the ram?
It is quicker to move the stack pointer than it is to allocate memory.
Allocating referenced objects is still fast in managed code, but changing
the stack pointer is still faster. Also taking into account that a method
knows which value types are created internally and thus they all get
allocated at once on entry to the method (or as part of their owning
object).
n!