1414namespace osrm ::util
1515{
1616
17- #if 1
18-
19- template <typename T, size_t MinItemsInBlock = 1024 >
17+ template <typename T>
2018class PoolAllocator ;
2119
22- template <typename T, size_t MinItemsInBlock = 1024 >
20+ template <typename T>
2321class MemoryManager
2422{
23+ private:
24+ constexpr static size_t MIN_ITEMS_IN_BLOCK = 1024 ;
2525public:
2626 static std::shared_ptr<MemoryManager> instance ()
2727 {
@@ -82,7 +82,7 @@ class MemoryManager
8282
8383 void allocate_block (size_t items_in_block)
8484 {
85- items_in_block = std::max (items_in_block, MinItemsInBlock );
85+ items_in_block = std::max (items_in_block, MIN_ITEMS_IN_BLOCK );
8686
8787 size_t block_size = items_in_block * sizeof (T);
8888 T *block = static_cast <T *>(std::malloc (block_size));
@@ -104,21 +104,21 @@ class MemoryManager
104104 size_t total_allocated_ = 0 ;
105105};
106106
107- template <typename T, size_t MinItemsInBlock >
107+ template <typename T>
108108class PoolAllocator
109109{
110110public:
111111 using value_type = T;
112112
113- PoolAllocator () noexcept : pool(MemoryManager<T, MinItemsInBlock >::instance()) {};
113+ PoolAllocator () noexcept : pool(MemoryManager<T>::instance()) {};
114114
115115 template <typename U>
116- PoolAllocator (const PoolAllocator<U> &) noexcept : pool(MemoryManager<T, MinItemsInBlock >::instance()) {}
116+ PoolAllocator (const PoolAllocator<U> &) noexcept : pool(MemoryManager<T>::instance()) {}
117117
118118 template <typename U>
119119 struct rebind
120120 {
121- using other = PoolAllocator<U, MinItemsInBlock >;
121+ using other = PoolAllocator<U>;
122122 };
123123
124124 T *allocate (std::size_t n)
@@ -139,13 +139,7 @@ class PoolAllocator
139139 PoolAllocator &operator =(PoolAllocator &&) noexcept = default ;
140140
141141private:
142- std::shared_ptr<MemoryManager<T, MinItemsInBlock>> pool;
143-
144- static size_t get_next_power_of_two_exponent (size_t n)
145- {
146- BOOST_ASSERT (n > 0 );
147- return (sizeof (size_t ) * 8 ) - std::countl_zero (n - 1 );
148- }
142+ std::shared_ptr<MemoryManager<T>> pool;
149143};
150144
151145template <typename T, typename U>
@@ -160,7 +154,4 @@ bool operator!=(const PoolAllocator<T> &, const PoolAllocator<U> &)
160154 return false ;
161155}
162156
163- #else
164- template <typename T> using PoolAllocator = std::allocator<T>;
165- #endif
166157} // namespace osrm::util
0 commit comments