Skip to content

Commit 1373f29

Browse files
committed
Further refine complex map examples and link the example presentation to the relevant uses-allocator construction section
1 parent ef668b1 commit 1373f29

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

doc/interprocess.qbk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4688,7 +4688,7 @@ pool is used for each node size. This is not possible if you try to share
46884688
a node allocator between processes. To achieve this sharing
46894689
[classref boost::interprocess::node_allocator node_allocator]
46904690
uses the segment manager's unique type allocation service
4691-
(see [link interprocess.managed_memory_segments.managed_memory_segment_object_construction.unique Unique instance construction] section).
4691+
(see [link interprocess.managed_memory_segment_object_construction.unique Unique instance construction] section).
46924692

46934693
In the initialization, a
46944694
[classref boost::interprocess::node_allocator node_allocator]
@@ -5226,7 +5226,8 @@ and the mapped type is a class that stores several containers:
52265226
[doc_complex_map]
52275227

52285228
This example can be simplified if the user designs a type compatible with the
5229-
uses-allocator construction. Simplifies code and allows more efficient
5229+
[link interprocess.managed_memory_segment_object_construction.uses_allocator uses-allocator construction].
5230+
This simplifies code and allows more efficient
52305231
operations like the use of transparent functions for lookups and insertions:
52315232

52325233
[import ../example/doc_complex_map_uses_allocator.cpp]

example/doc_complex_map.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class complex_data
4646
//->
4747
};
4848

49-
//Definition of the map holding a string as key and complex_data as mapped type
49+
//Definition of a shared memory map<string_t,complex_data...>
5050
typedef std::pair<const string_t, complex_data> map_value_type;
5151
typedef allocator<map_value_type, seg_mngr_t> map_value_type_allocator;
5252
typedef bc::map< string_t, complex_data, std::less<string_t>

example/doc_complex_map_uses_allocator.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@ class complex_data
4747
//->
4848
};
4949

50+
//<-
5051
struct lessthan //A transparent comparison functor
5152
{
5253
typedef void is_transparent;
5354
template<class T, class U> bool operator() (const T &t, const U &u) const { return t < u; }
5455
};
55-
56-
//Definition of the map holding a string as key and complex_data as mapped type
57-
typedef std::pair<const string_t, complex_data> map_value_type;
58-
typedef allocator<map_value_type, seg_mngr_t> map_value_type_allocator;
59-
typedef boost::container::map< string_t, complex_data, lessthan
60-
, map_value_type_allocator> complex_map_type;
56+
//->
57+
//Definition of a shared memory map<string_t, complex_data...> with transparent comparison
58+
typedef std::pair<const string_t, complex_data> map_value_type;
59+
typedef allocator<map_value_type, seg_mngr_t> map_value_type_allocator;
60+
//=typedef bc::map< string_t, complex_data, std::less<>
61+
//<-
62+
typedef bc::map< string_t, complex_data, lessthan
63+
//->
64+
, map_value_type_allocator> complex_map_type;
6165

6266
int main ()
6367
{
@@ -75,7 +79,7 @@ int main ()
7579
//Construct the map calling map(key_compare, allocator_type), the allocator argument is implicit
7680
complex_map_type *mymap = segment.construct<complex_map_type>("MyMap")();
7781

78-
//Take advantage of transparent insertion, string_t and complex_data are constructed with implicit allocators
82+
//Efficient transparent insertion, string_t and complex_data are constructed in-place with implicit allocators
7983
mymap->try_emplace("key_str", "default_name");
8084

8185
return 0;

0 commit comments

Comments
 (0)