VLink 2.0.0
A high-performance communication middleware
载入中...
搜索中...
未找到
vlink::SysSharemem类 参考final

Named cross-process shared memory backed by the OS IPC layer. 更多...

#include <sys_sharemem.h>

vlink::SysSharemem 的协作图:

Public 类型

enum  Mode : uint8_t { kReadOnly = 0 , kReadWrite = 1 }
 Access mode for the shared memory mapping. 更多...

Public 成员函数

 SysSharemem ()
 Default constructor. The object is not attached until create() or attach() is called.
 ~SysSharemem ()
 Destructor. Calls detach(true) if still attached.
bool create (const std::string &name, size_t size, Mode mode=kReadWrite)
 Creates a new named shared memory region of the given size and maps it.
bool attach (const std::string &name, Mode mode=kReadWrite)
 Attaches to an existing named shared memory region.
bool detach (bool force=true)
 Unmaps the shared memory region and optionally unlinks the OS object.
bool is_attached () const
 Returns true if the region is currently mapped.
void * data ()
 Returns a writable pointer to the beginning of the shared memory region.
const void * data () const
 Returns a read-only pointer to the beginning of the shared memory region.
size_t size () const
 Returns the size of the mapped region in bytes.

详细描述

Named cross-process shared memory backed by the OS IPC layer.

Provides a typed data() pointer into a shared memory region that is accessible by any process that attaches the same name.

成员枚举类型说明

◆ Mode

enum vlink::SysSharemem::Mode : uint8_t

Access mode for the shared memory mapping.

枚举值
kReadOnly 

Read-only mapping (PROT_READ)

kReadWrite 

Read-write mapping (PROT_READ | PROT_WRITE)

构造及析构函数说明

◆ SysSharemem()

vlink::SysSharemem::SysSharemem ( )

Default constructor. The object is not attached until create() or attach() is called.

这是这个函数的调用关系图:

◆ ~SysSharemem()

vlink::SysSharemem::~SysSharemem ( )

Destructor. Calls detach(true) if still attached.

成员函数说明

◆ attach()

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

Attaches to an existing named shared memory region.

The region must have been created by another process (or an earlier call to create()) before attach() can succeed.

参数
nameOS name of the shared memory object.
modeAccess mode (default: kReadWrite).
返回
true on success, false if the region does not exist or access is denied.

◆ create()

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

Creates a new named shared memory region of the given size and maps it.

Fails if a region with the same name already exists. The region is not zero-initialised.

参数
nameOS name for the shared memory object (POSIX: must start with '/').
sizeSize of the region in bytes.
modeAccess mode (default: kReadWrite).
返回
true on success, false on failure.
函数调用图:

◆ data() [1/2]

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

Returns a writable pointer to the beginning of the shared memory region.

返回
Pointer to the mapped region, or nullptr if not attached or in read-only mode (use the const overload for read-only access).

◆ data() [2/2]

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

Returns a read-only pointer to the beginning of the shared memory region.

返回
Const pointer to the mapped region, or nullptr if not attached.

◆ detach()

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

Unmaps the shared memory region and optionally unlinks the OS object.

After detach(), is_attached() returns false and data() returns nullptr.

参数
forceIf true, POSIX backends unlink the backing OS object. Set false to merely unmap without destroying the object (other processes keep access). On Windows this only closes the local mapping handle. Default: true.
返回
true on success, false if not attached or unmap failed.

◆ is_attached()

bool vlink::SysSharemem::is_attached ( ) const
nodiscard

Returns true if the region is currently mapped.

返回
true if attached (mapped), false otherwise.

◆ size()

size_t vlink::SysSharemem::size ( ) const
nodiscard

Returns the size of the mapped region in bytes.

返回
Region size in bytes, or 0 if not attached.
函数调用图:
这是这个函数的调用关系图:

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