diff --git a/include/engine/guidance/assemble_geometry.hpp b/include/engine/guidance/assemble_geometry.hpp index 386d39d8d..4001f6089 100644 --- a/include/engine/guidance/assemble_geometry.hpp +++ b/include/engine/guidance/assemble_geometry.hpp @@ -36,11 +36,6 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade, const bool reversed_target) { LegGeometry geometry; - geometry.locations.reserve(leg_data.size() + 2); - geometry.segment_distances.reserve(leg_data.size() + 1); - geometry.segment_offsets.reserve(leg_data.size() + 1); - geometry.annotations.reserve(leg_data.size() + 1); - geometry.node_ids.reserve(leg_data.size() + 2); // segment 0 first and last geometry.segment_offsets.push_back(0); diff --git a/include/util/pool_allocator.hpp b/include/util/pool_allocator.hpp index e010bfe3a..23b8737db 100644 --- a/include/util/pool_allocator.hpp +++ b/include/util/pool_allocator.hpp @@ -12,11 +12,21 @@ namespace osrm::util { -template class PoolAllocator +#if 1 +template class PoolAllocator { public: using value_type = T; + PoolAllocator() noexcept = default; + + template PoolAllocator(const PoolAllocator &) noexcept {} + + template struct rebind + { + using other = PoolAllocator; + }; + T *allocate(std::size_t n) { size_t free_list_index = get_next_power_of_two_exponent(n); @@ -56,28 +66,46 @@ template class PoolAllocator private: size_t get_next_power_of_two_exponent(size_t n) const { - return std::countr_zero(std::bit_ceil(n)); + BOOST_ASSERT(n > 0); + return (sizeof(size_t) * 8) - std::countl_zero(n - 1); } void allocate_block(size_t items_in_block) { - size_t block_size = std::max(items_in_block, (size_t)256) * sizeof(T); - T *block = static_cast(std::malloc(block_size)); + items_in_block = std::max(items_in_block, MinItemsInBlock); + size_t block_size = items_in_block * sizeof(T); + T *block = static_cast(std::aligned_alloc(alignof(T), block_size)); if (!block) { throw std::bad_alloc(); } + total_allocated_ += block_size; blocks_.push_back(block); - current_block_ = block; current_block_ptr_ = block; - current_block_left_items_ = block_size / sizeof(T); + current_block_left_items_ = items_in_block; } std::array, 32> free_lists_; std::vector blocks_; - T *current_block_ = nullptr; T *current_block_ptr_ = nullptr; size_t current_block_left_items_ = 0; + + size_t total_allocated_ = 0; }; +template +bool operator==(const PoolAllocator &, const PoolAllocator &) +{ + return true; +} + +template +bool operator!=(const PoolAllocator &, const PoolAllocator &) +{ + return false; +} + +#else +template using PoolAllocator = std::allocator; +#endif } // namespace osrm::util