13 #include <type_traits>
34 void*
get()
const {
return m_addr.get(); }
40 void operator()(
void*)
const;
43 SharedMemory() =
default;
45 SharedMemory(Handle&& handle,
void* addr) : m_handle{std::move(handle)}, m_addr{addr} {}
48 std::unique_ptr<void, Unmap> m_addr;
55 typedef typename std::aligned_storage<
sizeof(T), __alignof(T)>::type AlignedType;
62 template <
typename... Args>
65 new (obj.ptr()) T(std::forward<Args>(args)...);
66 obj.m_destruct =
true;
84 if (m_destruct &&
ptr()) {
90 T*
ptr()
const {
return reinterpret_cast<T*
>(m_shmem.
ptr()); }
94 T* operator->()
const {
return ptr(); }
95 T& operator*()
const {
return get(); }
98 explicit SharedObject(SharedMemory&& shmem) : m_shmem(std::move(shmem)) {}
100 SharedMemory m_shmem;
102 bool m_destruct =
false;
Named shared memory region.
static SharedMemory create(const std::string &name, std::size_t nb)
static SharedMemory open(const std::string &name)
Easy way to represent a C++ object as a shared memory region.
static SharedObject open(const std::string &name)
static SharedObject create(const std::string &name, Args &&... args)