I need to pass a C# memory object from one process to another (IPC)
I've just tried to serialize this object in a file and then deserialize it in my 2nd process with binary serialization (BinaryFormatter) in order to have good performance.
Unfortunately, the performance is not up to what I expected. As my object has a lot of information, serialization and deserialization takes too much times (the serialization of my object takes more than 1MB on my hard drive).
I have heard of
Memory-mapped files (MMF)
which seems to be one of the fastest method for IPC when the objects to share between process are simple. What is the fastest and easiest way to communicate between 2 processes in C#?
My object is only simple nested struct like this :
public struct Library
{
public Book[] books;
public string name;
}
public struct Book
{
public decimal price;
public string title;
public string author;
}
=> Is it possible to avoid serialization/deserialization and share this kind of object with MMF ?
=> What should be the characteristics of the shared object to avoid these operations of sérialization/deserialization ?
One more constraint : My first process is a C# 64 bits process and my 2nd process is a 32 bits one.
Thank you
You can't directly allocate objects in Memory Mapped File with C# (staying in safe code). So it means you need to have some sort of serialization to transfer of data between two applications.
Broad options:
I'd personally go with option 3 as it will give the most reliable and type safe gains if applicable to particular problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With