25 name = name.erase(0, 1);
27 std::string str_buf =
"/shm_" + regex_replace(name, std::regex(
"/"),
"_");
28 return shm_unlink(str_buf.c_str());
32 SharedMemory::SharedMemory(
int oflag, PERM perm)
42 SharedMemory::~SharedMemory()
52 SharedMemory::getSize()
const
59 SharedMemory::getPtr()
64 SharedMemoryPosix::SharedMemoryPosix(std::string name,
int oflag, PERM perm)
65 : SharedMemory(oflag, perm)
68 if (shm_name[0] ==
'/')
70 shm_name = shm_name.erase(0, 1);
75 SharedMemoryPosix::~SharedMemoryPosix()
81 SharedMemoryPosix::connect(
size_t size)
83 std::string str_buf =
"/shm_" + regex_replace(shm_name, std::regex(
"/"),
"_");
85 shm_fd = shm_open(str_buf.c_str(), shm_oflag,
static_cast<mode_t
>(shm_perm));
94 shm_size = stat.st_size;
97 if (stat.st_size < shm_size)
99 if (ftruncate(shm_fd, shm_size) < 0)
101 throw std::runtime_error(
"shm::getMemory(): Could not change shared memory size!");
104 fstat(shm_fd, &stat);
107 shm_ptr =
reinterpret_cast<unsigned char *
>(mmap(NULL,
109 PROT_READ|PROT_WRITE,
119 SharedMemoryPosix::disconnect()
126 SharedMemoryPosix::isDisconnected()
const
134 fstat(shm_fd, &stat);
135 if (stat.st_nlink <= 0)