Shared memory manager example
#include <algorithm>
#include <cstring>
#include <iostream>
int main(int argc, char** argv)
{
std::cout << "SharedMemory created!" << std::endl;
else
std::cout <<
"SharedMemory opened! Value = " << (
char*)buffer.
ptr() << std::endl;
std::cout << "Please enter anything to put into shared memory (several processes support). Enter '0' to exit..." << std::endl;
std::string line;
while (getline(std::cin, line))
{
if (line == "0")
break;
std::cout <<
"Old shared memory value = " << (
char*)buffer.
ptr() << std::endl;
std::memcpy(buffer.
ptr(), line.c_str(), std::min(line.size() + 1, buffer.
size()));
std::cout <<
"New shared memory value = " << (
char*)buffer.
ptr() << std::endl;
}
return 0;
}
void * ptr()
Get the shared memory block pointer.
bool owner() const
Get the shared memory owner flag (true if the new one was created, false if the existing one was open...
size_t size() const noexcept
Get the shared memory block size.
Shared memory manager definition.