|
VLink
2.0.0
A high-performance communication middleware
|
Named cross-process shared-memory region. 更多...
类 | |
| class | vlink::SysSharemem |
| Named cross-process shared-memory region with read-only or read-write mappings. 更多... | |
命名空间 | |
| vlink | |
Named cross-process shared-memory region.
vlink::SysSharemem wraps the platform's shared-memory API: shm_open + mmap on POSIX targets, CreateFileMapping + MapViewOfFile on Windows. The region appears in the kernel namespace under a caller-chosen name and any process that knows the name can map it into its own address space.
Memory layout exposed through data() and size():
* +---------------------------------------------------+ * | byte 0 | * | user payload (size = total bytes returned by | * | size()) | * | byte size-1 | * +---------------------------------------------------+ *
No internal header is reserved; the entire mapping is user payload. Place any synchronisation primitive (mutex, atomic counters, ring buffer indices) in the user region or in a companion SysSemaphore.
Lifecycle states observed by the wrapper:
| State | Entered by | is_attached() | data() |
|---|---|---|---|
| Detached | Construction, detach | false | nullptr |
| Created | create() | true | Pointer to mapping |
| Attached | attach() | true | Pointer to mapping |
Access modes accepted by create() and attach():
| Mode | POSIX flag | Effect |
|---|---|---|
kReadOnly | O_RDONLY | Maps with PROT_READ |
kReadWrite | O_RDWR | Maps with PROT_READ + PROT_WRITE |
'/'; Windows accepts arbitrary non-empty strings.