Boost logo

Boost Users :

From: Jason Sachs (jmsachs_at_[hidden])
Date: 2008-06-23 11:12:56


Ion Gaztañaga <igaztanaga <at> gmail.com> writes:
>
> //An allocator convertible to any allocator<T, segment_manager_t>
> type
> void_allocator alloc_inst (segment.get_segment_manager());
>
> //Construct the shared memory map and fill it
> complex_map_type *mymap = segment.construct<complex_map_type>
> //(object name), (first ctor parameter, second ctor parameter)
> ("MyMap")(std::less<char_string>(), 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()));


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net