By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,493 Members | 3,090 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,493 IT Pros & Developers. It's quick & easy.

Memory sharing between 2 C# applications

P: n/a
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
Dec 18 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Peri" <pe**@CSPL.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
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
Dec 18 '07 #2

P: n/a
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:00**********************************@microsof t.com...
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]
- mv*@spam.guard.caspershouse.com

"Peri" <pe**@CSPL.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>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

Dec 18 '07 #3

P: n/a
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" <pe**@CSPL.comwrote in message
news:OV**************@TK2MSFTNGP04.phx.gbl...
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:00**********************************@microsof t.com...
>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]
- mv*@spam.guard.caspershouse.com

"Peri" <pe**@CSPL.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>>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


Dec 18 '07 #4

P: n/a
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]
- mv*@spam.guard.caspershouse.com

"Rene" <a@b.comwrote in message
news:Ot**************@TK2MSFTNGP03.phx.gbl...
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" <pe**@CSPL.comwrote in message
news:OV**************@TK2MSFTNGP04.phx.gbl...
>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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:00**********************************@microsof t.com...
>>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]
- mv*@spam.guard.caspershouse.com

"Peri" <pe**@CSPL.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
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



Dec 18 '07 #5

P: n/a
On Dec 18, 6:33 am, "Peri" <p...@CSPL.comwrote:
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.
Dec 18 '07 #6

P: n/a
On 18 Dec, 12:33, "Peri" <p...@CSPL.comwrote:
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
Dec 19 '07 #7

P: n/a

"Peri" <pe**@CSPL.comwrote in message
news:OV**************@TK2MSFTNGP04.phx.gbl...
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 [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:00**********************************@microsof t.com...
>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]
- mv*@spam.guard.caspershouse.com

"Peri" <pe**@CSPL.comwrote in message
news:es**************@TK2MSFTNGP03.phx.gbl...
>>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


Dec 19 '07 #8

P: n/a
GG
If you are looking for IPC then check named pipes. You will need dot net
3.5 version. hope it helps.

*** Sent via Developersdex http://www.developersdex.com ***
Dec 20 '07 #9

P: n/a
Peri wrote:
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
Dec 22 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.