S
Sathyaish
And I've probably asked this, like, a thousand times.
In .net, a struct is a value type, so it gets stored on the stack.
struct foo
{
int a;
byte b;
}
In the above code, both variables, a and b, would get stored on the
stack. Therefore, the sizeof(foo) would be 5 bytes (or 8 bytes
depending on compiler switches that govern padding and byte alignment.
In .net, this would be the StructLayoutKindAttribute)
But that's beside the point. Let me get to my question.
In .net, a string is a reference type. So:
string bar = "CoT"; //Unicode encoding by default
would mean bar (4 bytes) on the stack that reference 8 bytes (2*
(3+'\0')) on the heap.
My question:
Where would a string that is a member of a struct be stored?
struct foo
{
string bar;
}
foo f;
f.bar = "CoT";
In .net, a struct is a value type, so it gets stored on the stack.
struct foo
{
int a;
byte b;
}
In the above code, both variables, a and b, would get stored on the
stack. Therefore, the sizeof(foo) would be 5 bytes (or 8 bytes
depending on compiler switches that govern padding and byte alignment.
In .net, this would be the StructLayoutKindAttribute)
But that's beside the point. Let me get to my question.
In .net, a string is a reference type. So:
string bar = "CoT"; //Unicode encoding by default
would mean bar (4 bytes) on the stack that reference 8 bytes (2*
(3+'\0')) on the heap.
My question:
Where would a string that is a member of a struct be stored?
struct foo
{
string bar;
}
foo f;
f.bar = "CoT";