G
Guest
I read somewhere that a bool is 1 byte unless if it's in a array, then it will be 2 bytes. is that true? if so, any explaination to why that is?
Daniel Jin said:I read somewhere that a bool is 1 byte unless if it's in a array,
then it will be 2 bytes. is that true? if so, any explaination to why
that is?
unless if it's in a array, then it will be 2 bytes. is that true?
I read somewhere that a bool is 1 byte unless if it's in a array, then it will be 2 bytes. is that true? if so, any explaination to why that is?
Bool size is 4 Bytes.
check this:
System.Runtime.InteropServices.Marshal.SizeOf(typeof(Boolean))
Marcin,
No, what you're getting here is the size of a bool when marshaled to a
native Win32 BOOL, which is indeed four bytes.
Try this instead
unsafe { Console.WriteLine( sizeof(bool) ); }
Mattias
Marcin GrzÄTbski said:Hi Mattias,
I think You're right...
I would go as far as to claim he is right. The managed and unmanaged
world is completly different and the Marshal.SizeOf lives in the unmanaged
realm.
Marcin Grzêbski said:Hi Andreas,
hmmm...
Could you tell me if there is any *sizeof* method that works with
managed value types (e.g. System.Drawing.Color) ?
William Stacey said:Yeh. However is it not true that because of alignment, the smallest thing
you can allocate is a 4 byte int. So I "think", internally, it is an int.
Not sure, but thought I came across this once. Please correct if in error
here. Cheers!
Andreas said:Marcin,
The sizeof operator is used to retrieve the size of a valuetype.
//Andreas
Color type looks as a standard struct type, so what is wrong?
Marcin,
It contains a field that's a reference type (specifically a private
string member called 'name'). sizeof (and unsafe code in general) only
works on value types that are only made up of other value types.
Mattias
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.