You have a number of problems. The obvious thing is that you are not creating your object. In the opaque form you are currently doing:
class Foo; Foo * p = get_memory(); p->bar = 5;
What you should do at least:
void * addr = get_memory(sizeof(Foo)); Foo * p = ::new (addr) Foo;
(Just replace Foo with LOCK for your situation.)
However, it gets complicated: vector and string require dynamic allocations. This memory must be in the same address space as your LOCK . So the standard way to solve this is to write your own dispenser and pass this:
template <template <typename> class Alloc> struct Lock { typedef std::basic_string<char, std::char_traits<char>, Alloc<char>> shared_string; shared_string name; shared_string type; std::vector<shared_string, Alloc<shared_string>> pids; };
Finally, you need to write an appropriate allocator class that puts the memory in the same address space as the one in which your LOCK object will eventually go:
template <typename T> class shared_allocator { } typedef Lock<shared_allocator> LOCK;
source share