My question is whether it is possible to determine the serialized size (in bytes) of the reference type.
Here is a situation:
I use the BinaryFormatter class to serialize the basic .NET types, for example, for example:
[Serializable]
public class Foo
{
public string Foo1 { get; set; }
public string Foo2 { get; set; }
}
I serialize each element into byte [], then add this segment to the end of the existing byte [] and optionally add a carriage return at the end of each segment to delimit objects.
For deserialization, I use Marshal.ReadByte () as follows:
List<byte> buffer = new List<byte>();
for (int i = 0; i < MapSize; i++)
{
byte b = Marshal.ReadByte(readPtr , i);
if (b != delim)
buffer.Add(b);
else
break;
}
readPtr = readPtr + buffer.Count + 1;
return buffer.ToArray();
, Marshal.Copy() , . , , , , ?
, . , BinaryFormatter - ? , , BinaryFormatter , , < > ?