Skip to content

Commit d1f04ab

Browse files
wip
1 parent c578698 commit d1f04ab

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

include/engine/guidance/assemble_geometry.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@ inline LegGeometry assembleGeometry(const datafacade::BaseDataFacade &facade,
3636
const bool reversed_target)
3737
{
3838
LegGeometry geometry;
39-
geometry.locations.reserve(leg_data.size() + 2);
40-
geometry.segment_distances.reserve(leg_data.size() + 1);
41-
geometry.segment_offsets.reserve(leg_data.size() + 1);
42-
geometry.annotations.reserve(leg_data.size() + 1);
43-
geometry.node_ids.reserve(leg_data.size() + 2);
4439

4540
// segment 0 first and last
4641
geometry.segment_offsets.push_back(0);

include/util/pool_allocator.hpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,21 @@
1212
namespace osrm::util
1313
{
1414

15-
template <typename T> class PoolAllocator
15+
#if 1
16+
template <typename T, size_t MinItemsInBlock = 1024> class PoolAllocator
1617
{
1718
public:
1819
using value_type = T;
1920

21+
PoolAllocator() noexcept = default;
22+
23+
template <typename U> PoolAllocator(const PoolAllocator<U> &) noexcept {}
24+
25+
template <typename U> struct rebind
26+
{
27+
using other = PoolAllocator<U, MinItemsInBlock>;
28+
};
29+
2030
T *allocate(std::size_t n)
2131
{
2232
size_t free_list_index = get_next_power_of_two_exponent(n);
@@ -56,28 +66,46 @@ template <typename T> class PoolAllocator
5666
private:
5767
size_t get_next_power_of_two_exponent(size_t n) const
5868
{
59-
return std::countr_zero(std::bit_ceil(n));
69+
BOOST_ASSERT(n > 0);
70+
return (sizeof(size_t) * 8) - std::countl_zero(n - 1);
6071
}
6172

6273
void allocate_block(size_t items_in_block)
6374
{
64-
size_t block_size = std::max(items_in_block, (size_t)256) * sizeof(T);
65-
T *block = static_cast<T *>(std::malloc(block_size));
75+
items_in_block = std::max(items_in_block, MinItemsInBlock);
76+
size_t block_size = items_in_block * sizeof(T);
77+
T *block = static_cast<T *>(std::aligned_alloc(alignof(T), block_size));
6678
if (!block)
6779
{
6880
throw std::bad_alloc();
6981
}
82+
total_allocated_ += block_size;
7083
blocks_.push_back(block);
71-
current_block_ = block;
7284
current_block_ptr_ = block;
73-
current_block_left_items_ = block_size / sizeof(T);
85+
current_block_left_items_ = items_in_block;
7486
}
7587

7688
std::array<std::vector<T *>, 32> free_lists_;
7789
std::vector<T *> blocks_;
78-
T *current_block_ = nullptr;
7990
T *current_block_ptr_ = nullptr;
8091
size_t current_block_left_items_ = 0;
92+
93+
size_t total_allocated_ = 0;
8194
};
8295

96+
template <typename T, typename U>
97+
bool operator==(const PoolAllocator<T> &, const PoolAllocator<U> &)
98+
{
99+
return true;
100+
}
101+
102+
template <typename T, typename U>
103+
bool operator!=(const PoolAllocator<T> &, const PoolAllocator<U> &)
104+
{
105+
return false;
106+
}
107+
108+
#else
109+
template <typename T> using PoolAllocator = std::allocator<T>;
110+
#endif
83111
} // namespace osrm::util

0 commit comments

Comments
 (0)