控制对内存映射文件的读/写(Windows)
您是否打算防止同时读取/写入由多个进程打开的文件映射内存?
例如,如果内存中的字符串是“hello”,并且一个进程在其上写入“hi...”,我是否正确地说,同时读取的另一个进程可能会获得像“hi.lo”这样的间歇值?
基本上我要问的是人们如何再次保护此类事物。您打算使用信号量吗?这些可以跨流程工作吗?
Are you meant to protect against simultanously reads/writes to file mapped memory that is open by multiple processes?
For example if a string in the memory is "hello" and one process writes "hi..." over it, am I correct to say that another process that reads at the same time may get an intermittant value like "hi.lo"?
Basically what I am asking is how do people protect again these sorts of things. Are you meant to use semaphores? Do these work across processes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,如果您需要防止多个写入者或避免读取部分更新,那么每个进程使用的共享互斥体/信号量将有助于控制对共享数据的访问。
在这篇 MSDN 文章的底部有一些示例代码可以执行此操作:内存映射.NET 4.0 中的文件
Yes, if you need to protect against multiple writers or avoid reading partial updates then a shared Mutex / Semaphore used by each process would work to control access to the shared data.
There is some sample code which does this at the bottom of this MSDN article: Memory-Mapped Files in .NET 4.0