getting the size of a structure?
what if you have a structure like this:
struct foo
{
public int A;
public char[] B;
}
the size of the structure obviously changes depending on the size of the char array inside it. Is there a "correct" way to get the size of the struct so that it would include the size of the character array?
sizeof() obviously will not work... i could check the length of the array at runtime to get the size of the struct, but i was just wondering if there is a function for doing this already
Re: getting the size of a structure?
aah Marshal.SizeOf () :D:D:D
Re: getting the size of a structure?
hmm actually for some reason Marshall.SizeOf() seems to only count 4 bytes for the character array regardless of how many items it has in it :sick:
Re: getting the size of a structure?
The size of that structure does NOT change depending on the size of the array. Arrays are reference type objects, so the structure only contains a reference to the array. That reference is 32-bits no matter how many elements the array has. If you want the size of the array then you need to multiply its Length by the size of its element type.