I want to share some objects between multiple programs using shared memory.
I’ve found example at this site. It doesn’t have any allocation of object, just direct addressing, but i want to create struct or class in shared memory.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because the memory is already allocated you want to use placement new:
Then, the new instance of
MyClasswill be constructed in memory pointed byptr.When the object is not needed, you have to manually call the destructor (without freeing the memory).