yello,
Quick Q:
With regards to ram use, there really isnt any memory savings if I use type
bool, vs int....... is there? If I remmeber correctly from a microcontroller
course, the smallest addressable unit is an int. All rules still apply for
todays machines, right?
Thanks in advance.
If you need to save memory by storing boolean values in a more compact
way use System.BitArray. It only uses 1 bit per boolean plus the usual
overhead for being a class.
Here is the size in bytes of the basic value types:
1 sbyte,byte,bool
2 short,ushort,char
4 int,uint,float
8 long,ulong,double
The following may vary depending on Hardware/Implementation, but I
will use my computer, an ordinary PC running in 32-bit mode using .Net
2.0 Beta 2.
IntPtr,Reference: 4 (On a PC running in 64-bit mode it would be 8)
Object Instance: 8 + size of fields (Minimum total size of 12, Always
divideable by 4)
Struct: size of fields (Minimum of 1)
Array: 12 bytes + size of content (Total size always divideable by 4,
Much like an object instance)
Examples:
// 8+4+2+2+1 = 18 => Round up to 20 bytes per instance
class Test
{
int A; short B; char c; byte d; byte e;
}
Test[] t = new Test[1000000]; // 12 + 4 * 1 000 000 bytes (references)
for(int i=0;i<t.Length;i++)
t
= new Test() // 20 * 1 000 000 bytes (instances)
//For a total of 24 000 012 bytes
// 4 + 2 + 2 + 1 = 9
struct Test2
{
int A; short B; char c; byte d; byte e;
}
Test2[] = new Test2[1000000] //12 + 10 000 000 bytes
// For a total of 10 000 012 bytes