Ion GaztaƱaga
//An allocator convertible to any allocator
type void_allocator alloc_inst (segment.get_segment_manager()); //Construct the shared memory map and fill it complex_map_type *mymap = segment.construct
//(object name), (first ctor parameter, second ctor parameter) ("MyMap")(std::less (), alloc_inst); for(int i = 0; i < 100; ++i){ //Both key(string) and value(complex_data) need an allocator in their constructors char_string key_object(alloc_inst); complex_data mapped_object(i, "default_name", alloc_inst); map_value_type value(key_object, mapped_object); //Modify values and insert them in the map mymap->insert(value); }
Thanks, that helps. I didn't know you could use void_allocators, I thought they had to be specific for each allocated type. One question: I noticed in the example you posted, that the lifetime of the allocator "alloc_inst" equals/exceeds the lifetime of the map and the values that are inserted into the map. Is this required, or can the allocator just be a temporary stack variable (as follows)? char_string key_object(void_allocator(segment.get_segment_manager()));