-1

My original question is here.

I'd like to write an array of objects into shared memory. Let's assume we know the starting address of the shared memory. How should I store the array of objects into the shared memory and manipulate the array later(e.g.,access one particular object in the array and even the fields of that object)? Do I have to serialize the objects into the memory and implement relevant access methods myself or does C++ have memory management mechanisms to deal with the details?

7
  • 1
    Could you post some code that you have tried? It seems like you have some misconceptions on things but it's hard to know without seeing your train of thought. Commented Nov 28, 2011 at 15:45
  • You need to search for a good tutorial on how to use shared memory, you're likely to understand more that way... Commented Nov 28, 2011 at 15:48
  • 1
    Shared Memory just ensures that you have a common block of memory which is accessible across different processes.Once You have a block of memory shared it is accessible just as local storage, there is nothing special about it then after. Commented Nov 28, 2011 at 15:52
  • @Pubby I'm still in the design phase and haven't started coding yet. Basically my question boils down to the following: when we ask our system to create an array of objects, it allocates a contiguous block of memory of its choice and stores our objects in its own way. Now I'd like to do the same(i.e., have the same ability to access our objects) except this time I want to store the array of objects in a contiguous block of memory of our choice(e.g., shared memory). Commented Nov 28, 2011 at 15:56
  • 1
    @Terry LiYifeng: Shared memory isn't choosing where to allocate. Usually you access the previously shared memory by an alias. If you want to place objects in previously allocated memory, shared or otherwise, search for "placement new" Commented Nov 28, 2011 at 16:08

1 Answer 1

1

This isn't a particularly thought out answer, but I can't see where you're stuck since you didn't provide any code to give us a hint.

There is a sample program here - Sample Shared Memory Program - with sufficient commenting to make you understand how to achieve what you're asking though.

So, I'd say read that through carefully and give it a shot :)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.