File indexing completed on 2025-02-22 10:09:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_INTERPROCESS_CACHED_NODE_ALLOCATOR_HPP
0012 #define BOOST_INTERPROCESS_CACHED_NODE_ALLOCATOR_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017 #
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/interprocess/detail/config_begin.hpp>
0023 #include <boost/interprocess/detail/workaround.hpp>
0024
0025 #include <boost/interprocess/interprocess_fwd.hpp>
0026 #include <boost/interprocess/allocators/detail/node_pool.hpp>
0027 #include <boost/interprocess/allocators/detail/allocator_common.hpp>
0028 #include <boost/interprocess/detail/workaround.hpp>
0029 #include <boost/interprocess/detail/utilities.hpp>
0030 #include <boost/interprocess/containers/version_type.hpp>
0031 #include <boost/interprocess/allocators/detail/node_tools.hpp>
0032 #include <cstddef>
0033
0034
0035
0036
0037 namespace boost {
0038 namespace interprocess {
0039
0040
0041 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0042
0043 namespace ipcdetail {
0044
0045 template < class T
0046 , class SegmentManager
0047 , std::size_t NodesPerBlock = 64
0048 >
0049 class cached_node_allocator_v1
0050 : public ipcdetail::cached_allocator_impl
0051 < T
0052 , ipcdetail::shared_node_pool
0053 < SegmentManager
0054 , sizeof_value<T>::value
0055 , NodesPerBlock
0056 >
0057 , 1>
0058 {
0059 public:
0060 typedef ipcdetail::cached_allocator_impl
0061 < T
0062 , ipcdetail::shared_node_pool
0063 < SegmentManager
0064 , sizeof_value<T>::value
0065 , NodesPerBlock
0066 >
0067 , 1> base_t;
0068
0069 template<class T2>
0070 struct rebind
0071 {
0072 typedef cached_node_allocator_v1
0073 <T2, SegmentManager, NodesPerBlock> other;
0074 };
0075
0076 typedef typename base_t::size_type size_type;
0077
0078 cached_node_allocator_v1(SegmentManager *segment_mngr,
0079 size_type max_cached_nodes = base_t::DEFAULT_MAX_CACHED_NODES)
0080 : base_t(segment_mngr, max_cached_nodes)
0081 {}
0082
0083 template<class T2>
0084 cached_node_allocator_v1
0085 (const cached_node_allocator_v1
0086 <T2, SegmentManager, NodesPerBlock> &other)
0087 : base_t(other)
0088 {}
0089 };
0090
0091 }
0092
0093 #endif
0094
0095 template < class T
0096 , class SegmentManager
0097 , std::size_t NodesPerBlock
0098 >
0099 class cached_node_allocator
0100 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0101 : public ipcdetail::cached_allocator_impl
0102 < T
0103 , ipcdetail::shared_node_pool
0104 < SegmentManager
0105 , sizeof_value<T>::value
0106 , NodesPerBlock
0107 >
0108 , 2>
0109 #endif
0110 {
0111
0112 #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0113 public:
0114 typedef ipcdetail::cached_allocator_impl
0115 < T
0116 , ipcdetail::shared_node_pool
0117 < SegmentManager
0118 , sizeof_value<T>::value
0119 , NodesPerBlock
0120 >
0121 , 2> base_t;
0122
0123 public:
0124 typedef boost::interprocess::version_type<cached_node_allocator, 2> version;
0125 typedef typename base_t::size_type size_type;
0126
0127 template<class T2>
0128 struct rebind
0129 {
0130 typedef cached_node_allocator<T2, SegmentManager, NodesPerBlock> other;
0131 };
0132
0133 cached_node_allocator(SegmentManager *segment_mngr,
0134 size_type max_cached_nodes = base_t::DEFAULT_MAX_CACHED_NODES)
0135 : base_t(segment_mngr, max_cached_nodes)
0136 {}
0137
0138 template<class T2>
0139 cached_node_allocator
0140 (const cached_node_allocator<T2, SegmentManager, NodesPerBlock> &other)
0141 : base_t(other)
0142 {}
0143
0144 #else
0145 public:
0146 typedef implementation_defined::segment_manager segment_manager;
0147 typedef segment_manager::void_pointer void_pointer;
0148 typedef implementation_defined::pointer pointer;
0149 typedef implementation_defined::const_pointer const_pointer;
0150 typedef T value_type;
0151 typedef typename ipcdetail::add_reference
0152 <value_type>::type reference;
0153 typedef typename ipcdetail::add_reference
0154 <const value_type>::type const_reference;
0155 typedef typename SegmentManager::size_type size_type;
0156 typedef typename SegmentManager::difference_type difference_type;
0157
0158
0159
0160 template<class T2>
0161 struct rebind
0162 {
0163 typedef cached_node_allocator<T2, SegmentManager> other;
0164 };
0165
0166 private:
0167
0168
0169 template<class T2, class SegmentManager2, std::size_t N2>
0170 cached_node_allocator& operator=
0171 (const cached_node_allocator<T2, SegmentManager2, N2>&);
0172
0173
0174
0175 cached_node_allocator& operator=(const cached_node_allocator&);
0176
0177 public:
0178
0179
0180
0181 cached_node_allocator(segment_manager *segment_mngr);
0182
0183
0184
0185 cached_node_allocator(const cached_node_allocator &other);
0186
0187
0188
0189
0190 template<class T2>
0191 cached_node_allocator
0192 (const cached_node_allocator<T2, SegmentManager, NodesPerBlock> &other);
0193
0194
0195
0196 ~cached_node_allocator();
0197
0198
0199
0200 node_pool_t* get_node_pool() const;
0201
0202
0203
0204 segment_manager* get_segment_manager()const;
0205
0206
0207
0208 size_type max_size() const;
0209
0210
0211
0212 pointer allocate(size_type count, cvoid_pointer hint = 0);
0213
0214
0215
0216 void deallocate(const pointer &ptr, size_type count);
0217
0218
0219
0220 void deallocate_free_blocks();
0221
0222
0223
0224 friend void swap(self_t &alloc1, self_t &alloc2);
0225
0226
0227
0228 pointer address(reference value) const;
0229
0230
0231
0232 const_pointer address(const_reference value) const;
0233
0234
0235
0236 void construct(const pointer &ptr, const_reference v);
0237
0238
0239
0240 void destroy(const pointer &ptr);
0241
0242
0243
0244
0245 size_type size(const pointer &p) const;
0246
0247 pointer allocation_command(boost::interprocess::allocation_type command,
0248 size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse);
0249
0250
0251
0252
0253
0254
0255
0256 void allocate_many(size_type elem_size, size_type num_elements, multiallocation_chain &chain);
0257
0258
0259
0260
0261 void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain);
0262
0263
0264
0265
0266
0267
0268
0269 void deallocate_many(multiallocation_chain &chain);
0270
0271
0272
0273
0274 pointer allocate_one();
0275
0276
0277
0278
0279
0280
0281
0282 multiallocation_chain allocate_individual(size_type num_elements);
0283
0284
0285
0286
0287 void deallocate_one(const pointer &p);
0288
0289
0290
0291
0292
0293
0294
0295 void deallocate_individual(multiallocation_chain it);
0296
0297
0298 void set_max_cached_nodes(size_type newmax);
0299
0300
0301
0302 size_type get_max_cached_nodes() const;
0303 #endif
0304 };
0305
0306 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0307
0308
0309
0310 template<class T, class S, std::size_t NPC> inline
0311 bool operator==(const cached_node_allocator<T, S, NPC> &alloc1,
0312 const cached_node_allocator<T, S, NPC> &alloc2);
0313
0314
0315
0316 template<class T, class S, std::size_t NPC> inline
0317 bool operator!=(const cached_node_allocator<T, S, NPC> &alloc1,
0318 const cached_node_allocator<T, S, NPC> &alloc2);
0319
0320 #endif
0321
0322 }
0323 }
0324
0325 #include <boost/interprocess/detail/config_end.hpp>
0326
0327 #endif
0328