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_ADAPTIVE_POOL_HPP
0012 #define BOOST_INTERPROCESS_CACHED_ADAPTIVE_POOL_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/adaptive_node_pool.hpp>
0027 #include <boost/interprocess/allocators/detail/allocator_common.hpp>
0028 #include <boost/interprocess/detail/utilities.hpp>
0029 #include <boost/interprocess/detail/workaround.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 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0041
0042 namespace ipcdetail {
0043
0044 template < class T
0045 , class SegmentManager
0046 , std::size_t NodesPerBlock = 64
0047 , std::size_t MaxFreeBlocks = 2
0048 , unsigned char OverheadPercent = 5
0049 >
0050 class cached_adaptive_pool_v1
0051 : public ipcdetail::cached_allocator_impl
0052 < T
0053 , ipcdetail::shared_adaptive_node_pool
0054 < SegmentManager
0055 , sizeof_value<T>::value
0056 , NodesPerBlock
0057 , MaxFreeBlocks
0058 , OverheadPercent
0059 >
0060 , 1>
0061 {
0062 public:
0063 typedef ipcdetail::cached_allocator_impl
0064 < T
0065 , ipcdetail::shared_adaptive_node_pool
0066 < SegmentManager
0067 , sizeof_value<T>::value
0068 , NodesPerBlock
0069 , MaxFreeBlocks
0070 , OverheadPercent
0071 >
0072 , 1> base_t;
0073
0074 template<class T2>
0075 struct rebind
0076 {
0077 typedef cached_adaptive_pool_v1
0078 <T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> other;
0079 };
0080
0081 typedef typename base_t::size_type size_type;
0082
0083 cached_adaptive_pool_v1(SegmentManager *segment_mngr,
0084 size_type max_cached_nodes = base_t::DEFAULT_MAX_CACHED_NODES)
0085 : base_t(segment_mngr, max_cached_nodes)
0086 {}
0087
0088 template<class T2>
0089 cached_adaptive_pool_v1
0090 (const cached_adaptive_pool_v1
0091 <T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> &other)
0092 : base_t(other)
0093 {}
0094 };
0095
0096 }
0097
0098 #endif
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117 template < class T
0118 , class SegmentManager
0119 , std::size_t NodesPerBlock
0120 , std::size_t MaxFreeBlocks
0121 , unsigned char OverheadPercent
0122 >
0123 class cached_adaptive_pool
0124 #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED)
0125 : public ipcdetail::cached_allocator_impl
0126 < T
0127 , ipcdetail::shared_adaptive_node_pool
0128 < SegmentManager
0129 , sizeof_value<T>::value
0130 , NodesPerBlock
0131 , MaxFreeBlocks
0132 , OverheadPercent
0133 >
0134 , 2>
0135 #endif
0136 {
0137
0138 #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0139 public:
0140 typedef ipcdetail::cached_allocator_impl
0141 < T
0142 , ipcdetail::shared_adaptive_node_pool
0143 < SegmentManager
0144 , sizeof_value<T>::value
0145 , NodesPerBlock
0146 , MaxFreeBlocks
0147 , OverheadPercent
0148 >
0149 , 2> base_t;
0150
0151 public:
0152 typedef boost::interprocess::version_type<cached_adaptive_pool, 2> version;
0153
0154 template<class T2>
0155 struct rebind
0156 {
0157 typedef cached_adaptive_pool
0158 <T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> other;
0159 };
0160
0161 cached_adaptive_pool(SegmentManager *segment_mngr,
0162 std::size_t max_cached_nodes = base_t::DEFAULT_MAX_CACHED_NODES)
0163 : base_t(segment_mngr, max_cached_nodes)
0164 {}
0165
0166 template<class T2>
0167 cached_adaptive_pool
0168 (const cached_adaptive_pool<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> &other)
0169 : base_t(other)
0170 {}
0171
0172 #else
0173 public:
0174 typedef implementation_defined::segment_manager segment_manager;
0175 typedef segment_manager::void_pointer void_pointer;
0176 typedef implementation_defined::pointer pointer;
0177 typedef implementation_defined::const_pointer const_pointer;
0178 typedef T value_type;
0179 typedef typename ipcdetail::add_reference
0180 <value_type>::type reference;
0181 typedef typename ipcdetail::add_reference
0182 <const value_type>::type const_reference;
0183 typedef typename segment_manager::size_type size_type;
0184 typedef typename segment_manager::difference_type difference_type;
0185
0186
0187
0188 template<class T2>
0189 struct rebind
0190 {
0191 typedef cached_adaptive_pool<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> other;
0192 };
0193
0194 private:
0195
0196
0197 template<class T2, class SegmentManager2, std::size_t N2, std::size_t F2, unsigned char OP2>
0198 cached_adaptive_pool& operator=
0199 (const cached_adaptive_pool<T2, SegmentManager2, N2, F2, OP2>&);
0200
0201
0202
0203 cached_adaptive_pool& operator=(const cached_adaptive_pool&);
0204
0205 public:
0206
0207
0208
0209 cached_adaptive_pool(segment_manager *segment_mngr);
0210
0211
0212
0213 cached_adaptive_pool(const cached_adaptive_pool &other);
0214
0215
0216
0217
0218 template<class T2>
0219 cached_adaptive_pool
0220 (const cached_adaptive_pool<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> &other);
0221
0222
0223
0224 ~cached_adaptive_pool();
0225
0226
0227
0228 node_pool_t* get_node_pool() const;
0229
0230
0231
0232 segment_manager* get_segment_manager()const;
0233
0234
0235
0236 size_type max_size() const;
0237
0238
0239
0240 pointer allocate(size_type count, cvoid_pointer hint = 0);
0241
0242
0243
0244 void deallocate(const pointer &ptr, size_type count);
0245
0246
0247
0248 void deallocate_free_blocks();
0249
0250
0251
0252 friend void swap(self_t &alloc1, self_t &alloc2);
0253
0254
0255
0256 pointer address(reference value) const;
0257
0258
0259
0260 const_pointer address(const_reference value) const;
0261
0262
0263
0264 void construct(const pointer &ptr, const_reference v);
0265
0266
0267
0268 void destroy(const pointer &ptr);
0269
0270
0271
0272
0273 size_type size(const pointer &p) const;
0274
0275 pointer allocation_command(boost::interprocess::allocation_type command,
0276 size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse);
0277
0278
0279
0280
0281
0282
0283
0284 void allocate_many(size_type elem_size, size_type num_elements, multiallocation_chain &chain);
0285
0286
0287
0288
0289 void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain);
0290
0291
0292
0293
0294
0295
0296
0297 void deallocate_many(multiallocation_chain &chain);
0298
0299
0300
0301
0302 pointer allocate_one();
0303
0304
0305
0306
0307
0308
0309
0310 multiallocation_chain allocate_individual(size_type num_elements);
0311
0312
0313
0314
0315 void deallocate_one(const pointer &p);
0316
0317
0318
0319
0320
0321
0322
0323 void deallocate_individual(multiallocation_chain &chain);
0324
0325
0326 void set_max_cached_nodes(size_type newmax);
0327
0328
0329
0330 size_type get_max_cached_nodes() const;
0331 #endif
0332 };
0333
0334 #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED
0335
0336
0337
0338 template<class T, class S, std::size_t NodesPerBlock, std::size_t F, std::size_t OP> inline
0339 bool operator==(const cached_adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc1,
0340 const cached_adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc2);
0341
0342
0343
0344 template<class T, class S, std::size_t NodesPerBlock, std::size_t F, std::size_t OP> inline
0345 bool operator!=(const cached_adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc1,
0346 const cached_adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc2);
0347
0348 #endif
0349
0350 }
0351 }
0352
0353
0354 #include <boost/interprocess/detail/config_end.hpp>
0355
0356 #endif
0357