Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software

Shared Memory

Is it posible to share a few objects between diferent proceses? I would like to cache some objects between several C# programs I'm writing.

Sharing Memory
Tuesday, May 4, 2004

Yes, I believe you can.  You will probably have to use remoting.

Wednesday, May 5, 2004

You could create a cache point within one process and give the others access to it via remoting, certainly, but be aware that any object you have to actually transfer over the wire must be serializable. You can't share the actual objects (ie maintain references to the same instance); you'd be sharing the data in the object.

However, you could create a server-activated remote object with an infinite lifetime (see the MSDN Remoting documentation for more details, it'd take too long to explain here). This will be a singleton object and all calls from all processes to the same endpoint will use the same object and hence share the same state. I can see problems with that approach, too.

Neil Hewitt
Wednesday, May 5, 2004

Its quite easy to share memory directly between c# processes using a memory mapped file and win32 api calls.

If you need the code email me

Gareth Allen
Thursday, May 27, 2004

*  Recent Topics

*  Fog Creek Home