方法:多个程序实例共享相同的数据 [英] How: multiple program instances sharing same data

查看:192
本文介绍了方法:多个程序实例共享相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望同一个.exe的多个实例运行并共享相同的

数据。我知道他们都可以同时访问同一个文件,没有

问题,但我想把这些数据放在内存中,他们可以全部使用

访问。看起来像是不必要的内存浪费让他们全部同时在RAM中维护他们自己的相同数据副本。


什么''实现这个目标的最好方法是什么?


我听说过内存映射文件,所以也许这就是答案。我已经听说.NET不允许共享内存,所以也许这是我唯一的选择

。我会想象制作一个DLL是没有用的,因为那只是

允许共享代码,而不是数据(对吗?)。


感谢任何帮助

I want multiple instances of the same .exe to run and share the same
data. I know they all can access the same file at the same time, no
problem, but I''d like to have this data in RAM, which they can all
access. It seems like a needless waste of memory to make them all
maintain their own copy of the same data in RAM at the same time.

What''s the best way to achieve this?

I''ve heard of memory mapped files, so maybe that''s the answer. I''ve
heard that .NET doesn''t allow shared memory, so maybe that''s my only
choice. I would imagine making a DLL wouldn''t help, since that just
allows shared code, not data (right?).

thanks for any help

推荐答案

2007-11-06 14:53:12 -0800,Zytan< zy ******* ***@gmail.com说:
On 2007-11-06 14:53:12 -0800, Zytan <zy**********@gmail.comsaid:

我希望同一个.exe的多个实例运行并共享相同的

数据。我知道他们都可以同时访问同一个文件,没有

问题,但我想把这些数据放在内存中,他们可以全部使用

访问。看起来像是不必要的内存浪费让他们全部同时在RAM中维护他们自己的相同数据副本。


什么''实现这个目标的最好方法是什么?


我听说过内存映射文件,所以也许这就是答案。我已经听说.NET不允许共享内存,所以也许这是我唯一的选择

。我会想象制作一个DLL无济于事,因为只有

允许共享代码,而不是数据(对吧?)。
I want multiple instances of the same .exe to run and share the same
data. I know they all can access the same file at the same time, no
problem, but I''d like to have this data in RAM, which they can all
access. It seems like a needless waste of memory to make them all
maintain their own copy of the same data in RAM at the same time.

What''s the best way to achieve this?

I''ve heard of memory mapped files, so maybe that''s the answer. I''ve
heard that .NET doesn''t allow shared memory, so maybe that''s my only
choice. I would imagine making a DLL wouldn''t help, since that just
allows shared code, not data (right?).



内存映射文件确实是解决问题的常用方法,但是你需要使用p / invoke来实现它和/或托管的C ++ DLL。


这就是说,除非你在谈论大量数据(比如说,

几百兆字节) ,我不知道在每个

申请中都有一个单独的副本一定是坏的。如果由于某种原因,数据非常大,你仍然可以共享相同的文件,但一次只能读取小的
部分。

如果没有更多细节,很难回答这个问题,但是在最常见的场景中我不认为是内存映射文件或
$ b需要$ b类似。


Pete

Memory mapped files are indeed a common way to address the issue, but
you''d have to implement that using p/invoke and/or a managed C++ DLL.

That said, unless you''re talking about a huge amount of data (say,
hundreds of megabytes), I don''t see that having a separate copy in each
application would necessarily be bad. If for some reason the data is
very large, you could still share the same file, but only read small
portions at a time.

It''s hard to answer the question without more specifics, but in the
most common scenarios I don''t think that a memory mapped file or
similar would be necessary.

Pete


11月6日下午5:53,Zytan< ; zytanlith ... @ gmail.comwrote:
On Nov 6, 5:53 pm, Zytan <zytanlith...@gmail.comwrote:

我希望同一个.exe的多个实例运行并共享相同的

数据。我知道他们都可以同时访问同一个文件,没有

问题,但我想把这些数据放在内存中,他们可以全部使用

访问。看起来像是不必要的内存浪费让他们全部同时在RAM中维护他们自己的相同数据副本。


什么''实现这个目标的最好方法是什么?


我听说过内存映射文件,所以也许这就是答案。我已经听说.NET不允许共享内存,所以也许这是我唯一的选择

。我会想象制作一个DLL是没有用的,因为那只是

允许共享代码,而不是数据(对吗?)。


感谢任何帮助
I want multiple instances of the same .exe to run and share the same
data. I know they all can access the same file at the same time, no
problem, but I''d like to have this data in RAM, which they can all
access. It seems like a needless waste of memory to make them all
maintain their own copy of the same data in RAM at the same time.

What''s the best way to achieve this?

I''ve heard of memory mapped files, so maybe that''s the answer. I''ve
heard that .NET doesn''t allow shared memory, so maybe that''s my only
choice. I would imagine making a DLL wouldn''t help, since that just
allows shared code, not data (right?).

thanks for any help



这里完全不可能了:如何使用

远程处理?我写了一份服务它与几个相同.exe的不同运行应用程序接口。所有的.exe都运行本地服务,因此它只是远程的。名字。


在你的情况下,每个应用程序可以调用远程访问器/修改器函数

来获取/设置值。应该会有性能损失,但我不确定这对你的问题是否重要。

Here''s a completely off the wall possibility : how about using
remoting ? I''ve written up a "service" that interfaces with several
different running apps of the same .exe. All of the .exe run local to
the service, so it''s only "remote" in name.

In your case, each app could call remoting accessor/modifier functions
to get/set the value. There should be a performance hit, but I''m not
sure if that''s important to your problem.


内存映射文件确实是解决问题的常用方法,但是
Memory mapped files are indeed a common way to address the issue, but

你必须使用p / invoke和/或托管C ++ DLL来实现它。
you''d have to implement that using p/invoke and/or a managed C++ DLL.



ok,我已经读过这个了。我知道这是一个选择。

ok, I''ve read about this already. I knew that was an option.


这就是说,除非你在谈论大量的数据(比如说,数百美元)兆字节),我不知道在每个

应用程序中有一个单独的副本一定是坏的。如果由于某种原因,数据非常大,你仍然可以共享同一个文件,但一次只能读取小的
部分。
That said, unless you''re talking about a huge amount of data (say,
hundreds of megabytes), I don''t see that having a separate copy in each
application would necessarily be bad. If for some reason the data is
very large, you could still share the same file, but only read small
portions at a time.



数据乘以正在运行的副本数量使得内存占地面积很大。


我考虑过一次只读取文件的一部分,但是它需要处理将文件数据转换为

内存中的可用数据,所以它不是不重要的。但是,可能。

The data multiplied by the # of copies running makes the memory
footprint significant.

I considered reading only portions of the file at a time, but it
requires processing to convert the file data into usable data in
memory, so it''s not trivial. But, possible.


如果没有更具体的细节,很难回答这个问题,但在

最常见的场景我不知道不要认为内存映射文件或

类似是必要的。
It''s hard to answer the question without more specifics, but in the
most common scenarios I don''t think that a memory mapped file or
similar would be necessary.



基本上好像它们都使用相同的数据库,它们可以是一个他们都可以访问的SQL

数据库,实际上但是,没有什么比这更复杂的东西更重要了。它只是一个数据的数组,足够大,由足够数量的程序共享

内存使用完全是浪费。


感谢您的回复

Zytan

It''s basically as if they all use the same database, it could be a SQL
database they all access, in fact, but it''s nothing heavy duty that
requires something so complex. It''s just an array of data that''s
sufficient large, shared by sufficient number of programs that the
memory usage is just completely wasteful.

thanks for your reply
Zytan


这篇关于方法:多个程序实例共享相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆