Memory sharing between 2 C# applications

P

Peri

Dear All,

Is there a way in which 2 application can share a common memory location to
access static data?

Say for example I have a product master data that is available in a single
place, and I have an application that uses this data to do its own
operation. I also have a similar kind of another application that uses the
same data for its another operation. Can we implement this in C#?

Regards,

Peri
 
N

Nicholas Paldino [.NET/C# MVP]

Peri,

Have you considered a database? One of the major features of a database
is to be a persistent store of data for use by multiple applications. You
can easily store state there that your other apps can use (assuming you are
accessing the same database) and update as well.

Sharing memory isn't a practical solution in .NET if you are going to
share complex data structures (as you would have to manage the serialization
to/from shared memory, and you would have to have some sort of locking
mechanism on that memory). You are better off having a third app domain
somewhere which will store the values/items you need, and then remote to
that app domain to get/update those values/items.
 
P

Peri

DB access will be very slow compared to accessing the memory. Only because
of this I am planning to have arrays similar to IMD(In-memory-database).
Since there will not be any write operation I need not get worried about
locking mechanism. It would be only read operation. If this is the case can
I do it in a single machine (All applications running in one machine)?

Regards,

Peri

Nicholas Paldino said:
Peri,

Have you considered a database? One of the major features of a
database is to be a persistent store of data for use by multiple
applications. You can easily store state there that your other apps can
use (assuming you are accessing the same database) and update as well.

Sharing memory isn't a practical solution in .NET if you are going to
share complex data structures (as you would have to manage the
serialization to/from shared memory, and you would have to have some sort
of locking mechanism on that memory). You are better off having a third
app domain somewhere which will store the values/items you need, and then
remote to that app domain to get/update those values/items.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peri said:
Dear All,

Is there a way in which 2 application can share a common memory location
to access static data?

Say for example I have a product master data that is available in a
single place, and I have an application that uses this data to do its own
operation. I also have a similar kind of another application that uses
the same data for its another operation. Can we implement this in C#?

Regards,

Peri
 
R

Rene

Is my understanding that you can have in memory data tables using a database
such as sql server (I am assuming that you would be able to do this with the
free express version too).



If you use this technique you won't be reading and writing to disk, you will
be reading and writing directly in and from memory.





Peri said:
DB access will be very slow compared to accessing the memory. Only because
of this I am planning to have arrays similar to IMD(In-memory-database).
Since there will not be any write operation I need not get worried about
locking mechanism. It would be only read operation. If this is the case
can I do it in a single machine (All applications running in one machine)?

Regards,

Peri

Nicholas Paldino said:
Peri,

Have you considered a database? One of the major features of a
database is to be a persistent store of data for use by multiple
applications. You can easily store state there that your other apps can
use (assuming you are accessing the same database) and update as well.

Sharing memory isn't a practical solution in .NET if you are going to
share complex data structures (as you would have to manage the
serialization to/from shared memory, and you would have to have some sort
of locking mechanism on that memory). You are better off having a third
app domain somewhere which will store the values/items you need, and then
remote to that app domain to get/update those values/items.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peri said:
Dear All,

Is there a way in which 2 application can share a common memory location
to access static data?

Say for example I have a product master data that is available in a
single place, and I have an application that uses this data to do its
own operation. I also have a similar kind of another application that
uses the same data for its another operation. Can we implement this in
C#?

Regards,

Peri
 
N

Nicholas Paldino [.NET/C# MVP]

I agree. For something like this, store the contents in a database,
query for the information once, and then access the values from the DataSet
(or whatever you stored the values to) from that point on.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rene said:
Is my understanding that you can have in memory data tables using a
database such as sql server (I am assuming that you would be able to do
this with the free express version too).



If you use this technique you won't be reading and writing to disk, you
will be reading and writing directly in and from memory.





Peri said:
DB access will be very slow compared to accessing the memory. Only
because of this I am planning to have arrays similar to
IMD(In-memory-database). Since there will not be any write operation I
need not get worried about locking mechanism. It would be only read
operation. If this is the case can I do it in a single machine (All
applications running in one machine)?

Regards,

Peri

Nicholas Paldino said:
Peri,

Have you considered a database? One of the major features of a
database is to be a persistent store of data for use by multiple
applications. You can easily store state there that your other apps can
use (assuming you are accessing the same database) and update as well.

Sharing memory isn't a practical solution in .NET if you are going to
share complex data structures (as you would have to manage the
serialization to/from shared memory, and you would have to have some
sort of locking mechanism on that memory). You are better off having a
third app domain somewhere which will store the values/items you need,
and then remote to that app domain to get/update those values/items.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Dear All,

Is there a way in which 2 application can share a common memory
location to access static data?

Say for example I have a product master data that is available in a
single place, and I have an application that uses this data to do its
own operation. I also have a similar kind of another application that
uses the same data for its another operation. Can we implement this in
C#?

Regards,

Peri
 
C

c.whelchel

Dear All,

Is there a way in which 2 application can share a common memory location to
access static data?

Say for example I have a product master data that is available in a single
place, and I have an application that uses this data to do its own
operation. I also have a similar kind of another application that uses the
same data for its another operation. Can we implement this in C#?

Regards,

Peri


Assuming you are doing this in Windows you can use the Win32 API calls
CreateFileMapping, MapViewOfFile and OpenFileMapping. Look them up on
pinvoke.net and msdn to find out how to setup a shared memory segment.
It's pretty simple but for static data the database maybe a better way
to go.
 
C

christery

Dear All,

Is there a way in which 2 application can share a common memory location to
access static data?

Say for example I have a product master data that is available in a single
place, and I have an application that uses this data to do its own
operation. I also have a similar kind of another application that uses the
same data for its another operation. Can we implement this in C#?

Regards,

Peri

Static data (thats not changing right?), read when app starts....from
the registry or .ini file comes to mind.
/CY
 
B

Ben Voigt [C++ MVP]

Peri said:
DB access will be very slow compared to accessing the memory. Only because
of this I am planning to have arrays similar to IMD(In-memory-database).
Since there will not be any write operation I need not get worried about
locking mechanism. It would be only read operation. If this is the case
can I do it in a single machine (All applications running in one machine)?

How much memory does the data take up? If it doesn't change, you can just
read it into each app, no need for sharing. If its too big for that, you
might use file APIs anyway, as Windows will use the file cache to avoid disk
access, and the file cache is shared between all processes.
Regards,

Peri

Nicholas Paldino said:
Peri,

Have you considered a database? One of the major features of a
database is to be a persistent store of data for use by multiple
applications. You can easily store state there that your other apps can
use (assuming you are accessing the same database) and update as well.

Sharing memory isn't a practical solution in .NET if you are going to
share complex data structures (as you would have to manage the
serialization to/from shared memory, and you would have to have some sort
of locking mechanism on that memory). You are better off having a third
app domain somewhere which will store the values/items you need, and then
remote to that app domain to get/update those values/items.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Peri said:
Dear All,

Is there a way in which 2 application can share a common memory location
to access static data?

Say for example I have a product master data that is available in a
single place, and I have an application that uses this data to do its
own operation. I also have a similar kind of another application that
uses the same data for its another operation. Can we implement this in
C#?

Regards,

Peri
 
G

GG

If you are looking for IPC then check named pipes. You will need dot net
3.5 version. hope it helps.
 
A

Arne Vajhøj

Peri said:
DB access will be very slow compared to accessing the memory. Only because
of this I am planning to have arrays similar to IMD(In-memory-database).
Since there will not be any write operation I need not get worried about
locking mechanism. It would be only read operation. If this is the case can
I do it in a single machine (All applications running in one machine)?

What about using a database with in memory tables like Oracle TimesTen ?

Arne
 

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