I am Serialising a Class containing List fields using Protobuf-net v2. In some cases, the List fields can get quite large and so my program fails with an Out Of Memory exception.
What I am now trying to implement is a process that would write the Proto-buf representation of my object to Disk, but using a buffer, so that I don't overuse my memory. So I started with:
using (var fs = File.OpenWrite(fullPath))
{
using (var bs = new BufferedStream(fs, 4096*2))
{
Serializer.Serialize(bs, myObject);
}
}
However, same OOM exception gets thrown. I suspect I need to write more code for the buffer, however, I am not even sure that what I am plan to do is a good idea and if any other methods exist, as I imagine, my problem is quite common.
Many thanks in advance.