|
VLink
2.0.0
A high-performance communication middleware
|
Named cross-process shared-memory region with read-only or read-write mappings. 更多...
#include <sys_sharemem.h>
Public 类型 | |
| enum | Mode : uint8_t { kReadOnly = 0 , kReadWrite = 1 } |
| Access mode applied to the mapping. 更多... | |
Public 成员函数 | |
| SysSharemem () | |
| Constructs a wrapper in the detached state. 更多... | |
| ~SysSharemem () | |
Destructor. Invokes detach(false) when the wrapper is still attached. 更多... | |
| bool | create (const std::string &name, size_t size, Mode mode=kReadWrite) |
Creates and maps a new shared-memory region of size bytes under name. 更多... | |
| bool | attach (const std::string &name, Mode mode=kReadWrite) |
| Attaches to an existing shared-memory region previously created with the same name. 更多... | |
| bool | detach (bool force=true) |
| Unmaps the region and optionally unlinks the kernel name. 更多... | |
| bool | is_attached () const |
| Reports whether the wrapper currently owns a mapping. 更多... | |
| void * | data () |
| Returns a writable pointer to the start of the mapping. 更多... | |
| const void * | data () const |
| Returns a read-only pointer to the start of the mapping. 更多... | |
| size_t | size () const |
| Returns the size of the mapping in bytes. 更多... | |
Named cross-process shared-memory region with read-only or read-write mappings.
Manages one mapping at a time; call detach() before re-attaching to a different region.
| enum vlink::SysSharemem::Mode : uint8_t |
Access mode applied to the mapping.
Enumerator names mirror the POSIX O_RDONLY / O_RDWR open flags. On Windows the implementation translates these to the equivalent CreateFileMapping / MapViewOfFile page-protection constants; the observable behaviour is identical across platforms.
| 枚举值 | |
|---|---|
| kReadOnly | Read-only mapping; writes through |
| kReadWrite | Read-write mapping (default). |
| vlink::SysSharemem::SysSharemem | ( | ) |
Constructs a wrapper in the detached state.
| vlink::SysSharemem::~SysSharemem | ( | ) |
Destructor. Invokes detach(false) when the wrapper is still attached.
| bool vlink::SysSharemem::attach | ( | const std::string & | name, |
| Mode | mode = kReadWrite |
||
| ) |
Attaches to an existing shared-memory region previously created with the same name.
| name | Kernel-name of the region. |
| mode | Access mode for the mapping. Default: kReadWrite. |
true on success. | bool vlink::SysSharemem::create | ( | const std::string & | name, |
| size_t | size, | ||
| Mode | mode = kReadWrite |
||
| ) |
Creates and maps a new shared-memory region of size bytes under name.
Fails when a region with name already exists in the kernel namespace. The supported POSIX/Windows backends provide zero-initialised storage.
| name | Kernel-name for the region. POSIX must begin with '/'. |
| size | Region size in bytes. |
| mode | Access mode for the mapping. Default: kReadWrite. |
true on success. | void* vlink::SysSharemem::data | ( | ) |
Returns a writable pointer to the start of the mapping.
nullptr when detached or in read-only mode. | const void* vlink::SysSharemem::data | ( | ) | const |
Returns a read-only pointer to the start of the mapping.
nullptr when detached. | bool vlink::SysSharemem::detach | ( | bool | force = true | ) |
Unmaps the region and optionally unlinks the kernel name.
| force | When true, POSIX backends call shm_unlink so the region is removed from the kernel namespace. Other processes that still hold mappings keep them. Windows merely closes the local mapping handle. Default: true. |
true on success. | bool vlink::SysSharemem::is_attached | ( | ) | const |
Reports whether the wrapper currently owns a mapping.
true after a successful create or attach. | size_t vlink::SysSharemem::size | ( | ) | const |
Returns the size of the mapping in bytes.
0 when detached.