我有一个 WCF 服务(在 NetTCP 上的控制台应用程序中实例化),该服务具有在负载上实例化的静态数据(大量)。
我同时运行此控制台应用程序的多个实例,并且所有实例都执行相同的静态数据初始化,有没有一种方法可以让我拥有单个数据源并在进程之间共享数据,以便每个进程都可以不是要消耗大量内存吗?
最佳答案
可以使用内存映射文件;但由于 Windows 保护应用程序的方式,每个进程都必须拥有自己的内存。
来自http://msdn.microsoft.com/en-us/library/dd997372.aspx :
Non-persisted files are memory-mapped files that are not associated with a file on a disk. When the last process has finished working with the file, the data is lost and the file is reclaimed by garbage collection. These files are suitable for creating shared memory for inter-process communications (IPC).
对于任何类型的“共享”数据,您都将承担同步访问的额外任务。
关于wcf - 在多个进程之间共享静态数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12533694/