Search code examples
c#windows-7named-pipesmemory-mapped-files

Can I share class instances between two processes on the same machine without having to serialize/deserialize?


I have fairly large collections of object instances (>100mb) that I need to share between two processes on the same machine. Is there a way to share such collections without having to serialize/deserialize?

I considered a message bus but then I would need to serialize/deserialize the object instances and that is a no-go because the overhead is too time consuming. Also memory mapped files seem to involve the serialization of the object instances to files.

I target C#/.Net 4.5 on a Windows 7 OS.

Thanks


Solution

  • You can't share a live object between processes.

    You can't force the .NET to keep an object in a memory mapped are of memory and/or to attach an object to the "data" present in a memory mapped area of memory.

    Once upon a time there was .NET Remoting to communicate between processes... It was very very low level... it is still present, but is obsolete. Through the use of internal black magic, sometimes (see https://stackoverflow.com/a/7553467/613130) instead of serializing/deserializing objects it is able to create a "proxy" on one side to access the data on the other side. Note that clearly this is slow. Ah... and proxied objects aren't really "local"... I think the non-owner has to make a call to the owner of the objects (the "server") to make any operation on the proxied objects. So they are "shared" like you would share a file on your HD: "client" computers can read it, but to read it, the "server" has to read it and send the read data to the "client".