veera sekhar kota wrote:
I read structs are stored at stack area or inline-heap based objects.
What is meant by inline-heap based objects? I didnt get that.
structs are allocated in exactly the way that ints or doubles are
allocated.
So, if you declare a class:
public class MyClass
{
private int _field1;
private double _field2;
private MyStructType _field3;
...
}
then when an instance of MyClass is created on the heap, the storage
reserved for that instance on the heap will contain space for an int, a
double, and a MyStructType.
This is different from the way that class instances are stored. If you
change your MyClass definition to
public class MyOtherClass
{
private int _field1;
private double _field2;
private MyThirdClass _field3;
...
}
then when an instance of MyOtherClass is created on the heap, the
storage reserved for that instance on the heap will contain space for
an int, a double, and a _reference_, which may be null or may contain a
reference to a MyThirdClass instance, which would be stored elsewhere
on the heap.
Notice that space for "struct" instances are stored _inline_, that is
alongside ints and doubles, whereas space for "class" instances are
allocated their own storage and references to them are stored _inline_.
Does that make more sense?