high6 Posted March 10, 2009 Share Posted March 10, 2009 How do you edit "malloc" to alloc shared memory?Am I going to have to dig the source out of the cpp file and redefine it? Link to comment
Killboy Posted March 10, 2009 Share Posted March 10, 2009 how about: #undef malloc#define malloc(size) supersharedalloc(size)void * supersharedalloc(size){... do whatever it takes to allocate shared memory here...return newptr;} Or you could try overloading new and delete, that's safer + you can just define malloc as new and free as delete and you covered both... Link to comment
high6 Posted March 10, 2009 Author Share Posted March 10, 2009 Actually don't really need to do this. Boost::Interprocess is what I need . Link to comment
high6 Posted March 10, 2009 Author Share Posted March 10, 2009 Also found this project.http://allocator.sourceforge.net/Not to sure on which I am going to use. From the looks of it, boost requires that you provide it a size. Which I want a dynamic allocator.Really what I want to do is something like.#pragma comment(linker, "/SECTION:.shared,RWS")#pragma data_seg(".shared")std::vector<int, somesharedallocator> * SharedVector;#pragma data_seg()int Main(){ if (SharedVector == NULL) //Did an instance of the dll already create the vector? SharedVector = new std::vector<int, somesharedallocator>();} Link to comment
Killboy Posted March 11, 2009 Share Posted March 11, 2009 This would be the STL specific approach:http://www.codeguru.com/cpp/cpp/cpp_mfc/st...ticle.php/c4079Not sure if you need a generic allocation version, but usually the STL comes in a library so overloading new and delete will not affect the allocator. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now