boost::interprocess mixing heap and shared memory ?

Working with boost::interprocess I came across the following question. using namespace boost::interprocess; // ... Assume that I've declared all the necessary allocators // ... for chars and std::pair<my_string,my_string> here typedef basic_string<char,my_char_allocator_t> my_string; typedef map<my_string,my_string,std::less<my_string>,my_string_string_allocator> my_map; managed_shared_memory shm(open_or_create,"BogusMemory",0x1000) my_map *the_map = some_how_construct_map_in_shared_memory(shm); // So now I have a map residing in shared memory // The only way to search within this map I could // find was the following. my_map::iterator i = the_map->find(my_string("BOGUS",my_char_allocator_t(shm))); This might throw since the search string is constructed within shared memory although it is only needed temporary and destructed right after the statement. Is there a way to use heap or stack memory for thinks like that ? Thank you very much O.

Oncaphillis wrote:
my_map::iterator i = the_map->find(my_string("BOGUS",my_char_allocator_t(shm)));
Is there a way to use heap or stack memory for thinks like that ?
This is an example of a larger problem that has worried me occasionally. For example, say I have a vector of structs sorted according to a string member; I might like to write: std::vector<my_struct> v; std::lower_bound(v.begin(), v.end(), std::string("hello"), COMP()); COMP needs to be a functor that can compare one of my structs with a std::string. That's not a problem, and in fact code like this will actually work with some standard libraries. But the standard requires that COMP takes two arguments of the same type, so standard library that did more checking would reject it. With algorithms like std::lower_bound it is of course possible to write one's own version that allows this sort of use. But there is more of a problem with member functions like map::find. Is anyone aware of any rationale for the current requirements? Phil.
participants (2)
-
Oncaphillis
-
Phil Endecott