Search code examples
c#.netserializationappdomainmemory-mapped-files

Moving large amounts of data between AppDomains


I have an application with two AppDomains. One of these AppDomains dynamically loads DLLs which do some calculations and produce a large amount of output data (stored in an EntityFramework EntityObject).

Thus far, I have just been "returning" this EntityObject to the other AppDomain when it calls the appropriate method. Of course, in reality, this is serializing the EntityObject and all of its data. As the amount of data this object holds has grown, this process has become a huge bottleneck in the application (sometimes taking minutes to serialize and deserialize).

I've seen in another StackOverflow post that the MemoryMappedFile might be a solution, but I'm not sure of the semantics to serialize and deserialize an object this way, and even if this is the best solution. I've also seen elsewhere that wrapping in an ObjectHandle supposedly allows the data to be shared in memory, but that didn't work when I tried it.

Thanks for any help.


Solution

  • As this answer suggests, serialization/deserialization generally cannot be avoided without a lot of refactoring. If your bottle neck is I/O, memory mapped files can help. However, if the bottle neck is CPU time spent serializing and deserializing, then try using a faster serialization method, such as Protobuf.Net.