CreateFileMapping用于在win32中创建共享内存
CreateFileMapping用于在win32中创建共享内存。是否需要同步共享内存读/写或者它是自动完成的?
CreateFileMapping is used to create shared memory in win32. Do need to synchronized shared memory read/write or it is done automatically ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的问题不清楚是否将其用于线程或进程之间的共享内存,因此请确定:对于不需要文件映射的线程,单个进程中的所有内存对所有线程都是可见的(并且需要同步) 。
要将其用于进程之间的共享内存:是的,您必须显式同步对其的访问,因为系统无法知道对其进行的连续写入是否应分组为单个事务。提示:要同步它们,您不能使用临界区(它们仅适用于进程内的线程),您可以使用:
http://msdn.microsoft.com/en-us/library/aa904937%28v=VS.85%29.aspx
Your question was not clear about whether you use this for shared memory between threads or processes, so just to be sure: for threads you dont need a file-mapping, all memory in a single process is visible to all threads (and needs sync).
To use it for shared memory between processes: yes you have to sync accesses to it explicitly because the system can not know whether consecutive writes to it are meant to be grouped as a single transaction or not. Tip to do this: To sync them you can not use criticalsections (they only work for threads within a process), you could use:
http://msdn.microsoft.com/en-us/library/aa904937%28v=VS.85%29.aspx