I'm comparing the size taken by serializing an object with 3 bytes of data. I'm creating 9 X 104 X 104 = 97,344 instances and serializing them. I would expect the space taken to be around 292,032 bytes with some misc serialization header stuff. I'm making
the same mistake elsewhere so that accounts for the (N bytes) starting 1.4M larger.
This takes the minimal amount of space. (1,655,687 bytes)
[code]
[Serializable]
public class MyObject
{
public byte _a;
public byte _b;
public byte _c;
}
[/code]
Followed by an array: (3,115,802 bytes)
[code]
[Serializable]
public class MyObject
{
public byte[] _data = new byte[3];
public MyObject()
{
_data[0] = 0;
_data[1] = 0;
_data[2] = 0;
}
}
[/code]
Followed by a list: (5,354,993 bytes)
[code]
[Serializable]
public class MyObject
{
public List<byte> _data = new List<byte>();
public MyObject()
{
_data.Add(0);
_data.Add(0);
_data.Add(0);
}
}
[/code]
How can I get the a fixed array to use the same space as the 3 byte variables?
[code]
BinaryFormatter bf =
new BinaryFormatter();
bf.Serialize(fs, myObject);
[/code]
When I have an object with 3 bytes, I want it to take 3 bytes of disk space.