Since the memory is already allocated, you want to use the new location :
void * ptr = shmat(shmid, 0, 0);
Then a new instance of MyClass
will be built in the memory marked with ptr
.
When an object is not needed, you must manually call the destructor (without freeing memory).
ptr->MyClass::~MyClass();
source share