G
Guest
Hi
Can anyone tell me how C# allocates memory for structs in C#? I am having
problems figuring out how much memory will be allocated. Consider the
following snippet
struct S1
{
int i;
char c;
}
I expect the size of this struct to be 6 bytes but it turns out to be 8
bytes. If I add a double then the size is 16 bytes.
struct S1
{
int i;
char c;
double d;
}
If after the double I include a byte then the size is 24 bytes !!!!!
struct S1
{
int a;
char c;
double d;
byte b;
}
Can anyone tell me why this strange behaviour? What is the rationale behind
such memory allocation?
Can anyone tell me how C# allocates memory for structs in C#? I am having
problems figuring out how much memory will be allocated. Consider the
following snippet
struct S1
{
int i;
char c;
}
I expect the size of this struct to be 6 bytes but it turns out to be 8
bytes. If I add a double then the size is 16 bytes.
struct S1
{
int i;
char c;
double d;
}
If after the double I include a byte then the size is 24 bytes !!!!!
struct S1
{
int a;
char c;
double d;
byte b;
}
Can anyone tell me why this strange behaviour? What is the rationale behind
such memory allocation?