[学习记录]C++进程间共享内存
来源:互联网 发布:antpool矿池挖矿软件 编辑:程序博客网 时间:2024/06/05 16:33
一个进程内创建共享内存空间,其余只用绑定这片内存即可实现进程间内存的共享。
即一个进程创建,其余进程打开。
定义句柄
HANDLE hMapFile = NULL;PVOID pView = NULL;
某一进程
创建共享内存空间
// Create the file mapping object.hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE,// Use paging file - shared memoryNULL,// Default security attributesPAGE_READWRITE,// Allow read and write access0,// High-order DWORD of file mapping max sizeMAP_SIZE,// Low-order DWORD of file mapping max sizeFULL_MAP_NAME// Name of the file mapping object);
指定内存的指针
// Map a view of the file mapping into the address space of the current// process.pView = MapViewOfFile(hMapFile,// Handle of the map objectFILE_MAP_ALL_ACCESS,// Read and write access0,// High-order DWORD of the file offsetVIEW_OFFSET,// Low-order DWORD of the file offsetVIEW_SIZE// The number of bytes to map to view);
共享所需数据
memcpy_s(pView, VIEW_SIZE, pszMessage, cbMessage);
其余进程
不用创建,只需打开被共享的那片内存即可
hMapFile = OpenFileMapping(FILE_MAP_READ, // Read accessFALSE, // Do not inherit the nameFULL_MAP_NAME // File mapping name);
// Map a view of the file mapping into the address space of the current// process.pView = MapViewOfFile(hMapFile,// Handle of the map objectFILE_MAP_ALL_ACCESS,// Read and write access0,// High-order DWORD of the file offsetVIEW_OFFSET,// Low-order DWORD of the file offsetVIEW_SIZE// The number of bytes to map to view);
共享所需数据
memcpy_s(pView, VIEW_SIZE, pszMessage, cbMessage);
共享内存的保护则后续再议~~~~~
0 0
- [学习记录]C++进程间共享内存
- linux c 共享内存编程学习记录
- 进程间通信笔记-记录上锁&&信号量&&共享内存
- 进程间共享内存
- 进程间共享内存
- linux进程间的通信(C): 共享内存
- linux进程间的通信(C): 共享内存
- 进程间通信:共享内存Shmem.c分析
- linux进程间的通信(C): 共享内存
- 【C++】使用共享内存实现进程间通信
- linux c之使用共享内存实现进程间通信
- linux进程间的通信(C): 共享内存
- C++:共享内存(进程间通讯)(转载)
- 进程间通信学习小结(共享内存)
- 进程间通信学习小结(共享内存)
- 进程间通信学习小结(共享内存)
- 进程间通信学习小结(共享内存)
- 进程间通信学习笔记三(共享内存通信)
- fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- SWFUpload flash文件上传使用集锦
- Jtag的各种引脚定义
- 移动表空间所使用的脚本以及语句
- 自动生成Linux下Makefile全攻略(下)
- [学习记录]C++进程间共享内存
- 从头到尾彻底解析哈希表算法
- 散列表(哈希表)
- iOS多线程编程之NSOperation和NSOperationQueue的使用
- scala扩展性
- 机器学习中的超平面
- kali下练习php
- 各种运算符注意事项
- 设计模式深入学习IOS版(8)架构设计