0

Please help to write c++ allocator for std::vector< nIcon*> class.

All examples i find shows just what methods i need to overwrite, not code examples.

I need to implement allocator using shared memory on windows (using CreateFileMapping and MapViewOfFile)

3
  • I notice that your vector contains pointers to nicon class. Are you sure that you want the pointers to be allocated from mapped memory, or do you want your icon themselves to be allocated from mapped memory? Commented Mar 15, 2011 at 14:31
  • Putting the standard class objects into shared memory won't work anyway. You cannot always get the same memory address in every process, and when the address is different all the pointers in the objects will break. Commented Mar 15, 2011 at 14:32
  • Thanks, yes nIcon is a class, as i can read the manual i can allocate memory for user defined classes using std vector combined with shared memory management (but without complex examples). What other methods can be used here to share such type between multiple processes? In my case in dynamically loaded dll i need to give access for every dll process attach. Commented Mar 15, 2011 at 15:13

2 Answers 2

3

May I suggest you look at the boost interprocess library? It allows you to create allocators using shared memory.

I've seen some examples around, I would say just look a bit more. I agree that none of them do a perfect job, thus I won't recommend any in particular. Though beyond just implementing the small set of functions there is really nothing to it (provided you don't need to implement one for map).

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

1 Comment

Yes, i looked at it, but i can't compile it under C++ Builder 2010. It fails with various errors, because standard cbuilder's package does not contain interprocess library, so i copyed one from newest library. Even replacing all boost in cbuilder did not make the work, because RTL/VCL is based on earlier version of boost. I'am now looking at POCO library, but anyone have success with it using c builder?
0

You would use:

std::vector< nicon *, MyAllocator >

For how you would write MyAllocator

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.