Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,
I don't know how many times this question has been asked in any .NET Forum, but still i have certain doubts regarding value types storage.
In almost every book (I read)it is written that value types are going to be stored in Stack. But in some articles i read "value types are stored where they are declared" is that true ?
If it is true then valu types declared in class will get stored in Heap.
And GC will deallocate them.
So what about the performance whenever we are using value types in class
Boxing is going to happen ? What happening inside ? Please i require more information regarding these as i couldn't find it.

Posted

1 solution

Sandeep Akhare wrote:
If it is true then valu types declared in class will get stored in Heap.


Only if the object of the class they are members of is allocated on the managed heap.
What if they are members of a value class?

Sandeep Akhare wrote:
And GC will deallocate them.


The GC only manages objects allocated on the managed heap.

Sandeep Akhare wrote:
So what about the performance whenever we are using value types in class


Value types are passed by value - that means a copy has to be made
every time a value type object is passed. That's going to be slower
than passing a reference I would guess. If value types are members of a
ref class then there's no difference - the ref class object holds the value
type objects.

Mark

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900