VLink  2.0.0
A high-performance communication middleware
vlink::SysSharemem类 参考final

Named cross-process shared-memory region with read-only or read-write mappings. 更多...

#include <sys_sharemem.h>

vlink::SysSharemem 的协作图:

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.

成员枚举类型说明

◆ Mode

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 data() are undefined.

kReadWrite 

Read-write mapping (default).

构造及析构函数说明

◆ SysSharemem()

vlink::SysSharemem::SysSharemem ( )

Constructs a wrapper in the detached state.

◆ ~SysSharemem()

vlink::SysSharemem::~SysSharemem ( )

Destructor. Invokes detach(false) when the wrapper is still attached.

成员函数说明

◆ attach()

bool vlink::SysSharemem::attach ( const std::string &  name,
Mode  mode = kReadWrite 
)

Attaches to an existing shared-memory region previously created with the same name.

参数
nameKernel-name of the region.
modeAccess mode for the mapping. Default: kReadWrite.
返回
true on success.

◆ create()

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.

参数
nameKernel-name for the region. POSIX must begin with '/'.
sizeRegion size in bytes.
modeAccess mode for the mapping. Default: kReadWrite.
返回
true on success.

◆ data() [1/2]

void* vlink::SysSharemem::data ( )

Returns a writable pointer to the start of the mapping.

返回
Mapping base pointer; nullptr when detached or in read-only mode.

◆ data() [2/2]

const void* vlink::SysSharemem::data ( ) const

Returns a read-only pointer to the start of the mapping.

返回
Const mapping base pointer; nullptr when detached.

◆ detach()

bool vlink::SysSharemem::detach ( bool  force = true)

Unmaps the region and optionally unlinks the kernel name.

参数
forceWhen 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.

◆ is_attached()

bool vlink::SysSharemem::is_attached ( ) const

Reports whether the wrapper currently owns a mapping.

返回
true after a successful create or attach.

◆ size()

size_t vlink::SysSharemem::size ( ) const

Returns the size of the mapping in bytes.

返回
Region size; 0 when detached.

该类的文档由以下文件生成: