Hi,
I am trying to optimize a class that serializes objects in binary format and writes them in a file. I am currently using a FileStream (in sync mode because of the size of my objects) and a BinaryWriter. Here's what my class looks like:
public class MyClass
{
private readonly BinaryWriter m_binaryWriter;
private readonly Stream m_stream;
public MyClass()
{
// Leave FileStream in synchronous mode for performance issue (faster in sync mode)
FileStream fileStream = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.ReadWrite, maxSize, false);
m_stream = fileStream;
m_binaryWriter = new BinaryWriter(m_stream);
}
public void SerializeObject(IMySerializableObject serializableObject)
{
serializableObject.Serialize(m_binaryWriter);
m_stream.Flush();
}
}
A profiler run on this code shows good performance but I was wondering if there are other objects (or techniques) that I could use to improve the performance of this class.