In all examples of boost interprocess, I only see it being initialized in main()
.
#include <boost/interprocess/managed_shared_memory.hpp>
#include <iostream>
using namespace boost::interprocess;
int main()
{
shared_memory_object::remove("Boost");
managed_shared_memory managed_shm(open_or_create, "Boost", 1024);
int *i = managed_shm.construct<int>("Integer")(99);
std::cout << *i << '\n';
std::pair<int*, std::size_t> p = managed_shm.find<int>("Integer");
if (p.first)
std::cout << *p.first << '\n';
}
Rather than specifically a boost question, this is more of a C++ question where I know i can create an object and initialize managed_shm
using the initialization list, but I want to know if there is a way to declare it like managed_shared_memory * managed_shm;
and later initialize it like managed_shm = new managed_shm(open_or_create, "Boost", 1024);
?
I have seen the managed_shared_memory
header, and they didn't seem to provide any option to do so.