Shared memory - how to implement in .NET 2.0/3.0

G

Guest

I am coding a dozen "background" realtime apps for factory automation in .NET
2.0.

The apps need to share a common memory as there are lots of variables to be
shared (and synchronized of course).
I need distinct apps for reasons like user interaction/access rights, error
compartments, and because the size of the code, access to various ports, ...

In the end the apps should run as Windows Service(s).

How can I implement shared memory using .NET 2.0/3.0?

thanks herbert
 
M

Michael Nemtsev

Hello herbert,

h> The apps need to share a common memory as there are lots of variables
h> to be shared (and synchronized of course).

Shared among who? How much your app is distributed?
For example you can use MMF http://groups.google.com/groups/search?q=dotnet+Memory+mapped+file&
but I'm not sure that is the right thing for u

h> I need distinct apps for reasons like user interaction/access rights,
h> error compartments, and because the size of the code, access to various
h> ports, ...

So, u need the set of control services? how shared memory will help u here?

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
G

Guest

Thank you, Michael.

this looks like a big stumbling block for me. I do .NET since 2002, yet it
is my only language so I don't have any C/C++/Win32 knowledge. Is there an
intro article about memory mapped files?

I did other operating systems before where data structures could be compiled
into .dlls, loaded into memory and accessed by all apps which were linked
against this .dll

Basically my IO apps read hundreds of relais, opto couplers and the like and
need to offer this knowledge to other apps which draw conclusions, do
emergency halts, and some other serious stuff.

I do not want to send all the data to all the possible recipients using
network protocols, and I do not want to duplicate data inside a single
computer.

It also needs remote events from server to clients, which I do using .NET
remoting while waiting for Indigo to pass the bleeding edge. (aka books and
samples about WCF).

best regards herbert
 
M

Michael Nemtsev

Hello herbert,

h> this looks like a big stumbling block for me. I do .NET since 2002,
h> yet it is my only language so I don't have any C/C++/Win32 knowledge.
h> Is there an intro article about memory mapped files?

See the MSDN for more details about MMF

So, probably you need Singleton class
h> I do not want to send all the data to all the possible recipients
h> using network protocols, and I do not want to duplicate data inside a
h> single computer.

How are u going to communicate with you class if u don't want to send data
to recipients?

h> It also needs remote events from server to clients, which I do using
h> .NET remoting while waiting for Indigo to pass the bleeding edge.
h> (aka books and samples about WCF).


Thus just create Singleton service which will maintain your shared data and
choose appropriate IPC way for communications

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
L

Leon Lambert

Its not too hard there are lots of examples around. Sharing data
amongst many applications via shared memory is reasonably common thing
to do. The way we did it was to have a dll written in unmanaged C++.
With .Net 2.0 it was real easy to use the dll in managed C++. In our
case .Net is only one development environment to use the shared memory.
We also use VB6, C++, Labview, and Java. Our shared memory can also be
shared to other machines so applications can be distributed. It uses an
replication scheme to manage this. Bottom line is though you will
probably have to learn C++ and Win32 APIs to do this. The really hard
part though is doing things in a very concurrency safe scheme. Unless
you are really familiar with Mutexes and NT events you might have a very
difficult time to get it safe. Also creating a shared memory manager
with compaction is also tricky especially if any of your applications
are soft real time like ours. I have a solid code base for dealing with
all this and would live to open source it but can't because i used
company tools to make it. Someday i will start from scratch on my own
machine on my own time to create a new code base so i can open source
it. That may be a while though.

Hope this helps
Leon Lambert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top