summaryrefslogtreecommitdiffstats
path: root/vespalib/src
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib/src')
-rw-r--r--vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp2
-rw-r--r--vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp2
-rw-r--r--vespalib/src/tests/datastore/unique_store/unique_store_test.cpp17
-rw-r--r--vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp15
-rw-r--r--vespalib/src/vespa/vespalib/datastore/CMakeLists.txt1
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.cpp8
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.h6
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store.hpp8
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_allocator.h8
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_allocator.hpp5
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.cpp25
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.h27
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.hpp29
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.cpp22
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h12
-rw-r--r--vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.hpp6
16 files changed, 160 insertions, 33 deletions
diff --git a/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp b/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp
index 417b92af9ac..599cb209e6c 100644
--- a/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp
+++ b/vespalib/src/tests/datastore/fixed_size_hash_map/fixed_size_hash_map_test.cpp
@@ -68,7 +68,7 @@ struct DataStoreFixedSizeHashTest : public ::testing::Test
DataStoreFixedSizeHashTest::DataStoreFixedSizeHashTest()
: _generation_handler(),
_generation_holder(),
- _allocator(),
+ _allocator({}),
_store(_allocator.get_data_store()),
_comp(std::make_unique<MyCompare>(_store)),
_hash_map(),
diff --git a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp
index 796e19a97d1..13f9ae251b6 100644
--- a/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp
+++ b/vespalib/src/tests/datastore/sharded_hash_map/sharded_hash_map_test.cpp
@@ -132,7 +132,7 @@ struct DataStoreShardedHashTest : public ::testing::Test
DataStoreShardedHashTest::DataStoreShardedHashTest()
: _generationHandler(),
- _allocator(),
+ _allocator({}),
_store(_allocator.get_data_store()),
_hash_map(std::make_unique<MyCompare>(_store)),
_writer(1, 128_Ki),
diff --git a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp
index 917c91f2dff..7f279689985 100644
--- a/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp
+++ b/vespalib/src/tests/datastore/unique_store/unique_store_test.cpp
@@ -9,6 +9,7 @@
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/test/datastore/buffer_stats.h>
#include <vespa/vespalib/test/insertion_operators.h>
+#include <vespa/vespalib/test/memory_allocator_observer.h>
#include <vespa/vespalib/util/traits.h>
#include <vector>
@@ -21,6 +22,9 @@ using namespace vespalib::datastore;
using vespalib::ArrayRef;
using generation_t = vespalib::GenerationHandler::generation_t;
using vespalib::datastore::test::BufferStats;
+using vespalib::alloc::MemoryAllocator;
+using vespalib::alloc::test::MemoryAllocatorObserver;
+using AllocStats = MemoryAllocatorObserver::Stats;
template <typename UniqueStoreT>
struct TestBaseValues {
@@ -39,6 +43,7 @@ struct TestBase : public ::testing::Test {
using ReferenceStoreValueType = std::conditional_t<std::is_same_v<ValueType, const char *>, std::string, ValueType>;
using ReferenceStore = std::map<EntryRef, std::pair<ReferenceStoreValueType,uint32_t>>;
+ AllocStats stats;
UniqueStoreType store;
ReferenceStore refStore;
generation_t generation;
@@ -148,7 +153,8 @@ struct TestBase : public ::testing::Test {
template <typename UniqueStoreTypeAndDictionaryType>
TestBase<UniqueStoreTypeAndDictionaryType>::TestBase()
- : store(),
+ : stats(),
+ store(std::make_unique<MemoryAllocatorObserver>(stats)),
refStore(),
generation(1)
{
@@ -424,6 +430,15 @@ TYPED_TEST(TestBase, store_can_be_enumerated)
EXPECT_EQ(2u, enumValue2);
}
+TYPED_TEST(TestBase, provided_memory_allocator_is_used)
+{
+ if constexpr (std::is_same_v<const char *, typename TestFixture::ValueType>) {
+ EXPECT_EQ(AllocStats(18, 0), this->stats);
+ } else {
+ EXPECT_EQ(AllocStats(1, 0), this->stats);
+ }
+}
+
#pragma GCC diagnostic pop
TEST_F(DoubleTest, nan_is_handled)
diff --git a/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp b/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp
index 158b85f6bf5..21330c22166 100644
--- a/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp
+++ b/vespalib/src/tests/datastore/unique_store_string_allocator/unique_store_string_allocator_test.cpp
@@ -4,6 +4,7 @@
#include <vespa/vespalib/gtest/gtest.h>
#include <vespa/vespalib/test/datastore/buffer_stats.h>
#include <vespa/vespalib/test/insertion_operators.h>
+#include <vespa/vespalib/test/memory_allocator_observer.h>
#include <vespa/vespalib/util/traits.h>
#include <vector>
@@ -11,6 +12,10 @@ using namespace vespalib::datastore;
using vespalib::MemoryUsage;
using generation_t = vespalib::GenerationHandler::generation_t;
using BufferStats = vespalib::datastore::test::BufferStats;
+using vespalib::alloc::MemoryAllocator;
+using vespalib::alloc::test::MemoryAllocatorObserver;
+using AllocStats = MemoryAllocatorObserver::Stats;
+
namespace {
@@ -24,10 +29,12 @@ template <typename RefT = EntryRefT<22>>
struct TestBase : public ::testing::Test {
using EntryRefType = RefT;
+ AllocStats stats;
UniqueStoreStringAllocator<EntryRefType> allocator;
generation_t generation;
TestBase()
- : allocator(),
+ : stats(),
+ allocator(std::make_unique<MemoryAllocatorObserver>(stats)),
generation(1)
{}
void assert_add(const char *input) {
@@ -170,6 +177,11 @@ TEST_F(StringTest, free_list_is_never_used_for_move)
assert_buffer_state(ref2, BufferStats().used(4).hold(0).dead(2).extra_used(2002));
}
+TEST_F(StringTest, provided_memory_allocator_is_used)
+{
+ EXPECT_EQ(AllocStats(18, 0), stats);
+}
+
TEST_F(SmallOffsetStringTest, new_underlying_buffer_is_allocated_when_current_is_full)
{
uint32_t first_buffer_id = get_buffer_id(add(small.c_str()));
@@ -184,6 +196,7 @@ TEST_F(SmallOffsetStringTest, new_underlying_buffer_is_allocated_when_current_is
uint32_t buffer_id = get_buffer_id(add(small.c_str()));
EXPECT_EQ(second_buffer_id, buffer_id);
}
+ EXPECT_LT(18, stats.alloc_cnt);
}
GTEST_MAIN_RUN_ALL_TESTS()
diff --git a/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt b/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt
index d628843279d..5ff1eab61b8 100644
--- a/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt
+++ b/vespalib/src/vespa/vespalib/datastore/CMakeLists.txt
@@ -14,6 +14,7 @@ vespa_add_library(vespalib_vespalib_datastore OBJECT
fixed_size_hash_map.cpp
sharded_hash_map.cpp
unique_store.cpp
+ unique_store_buffer_type.cpp
unique_store_string_allocator.cpp
DEPENDS
)
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.cpp b/vespalib/src/vespa/vespalib/datastore/unique_store.cpp
index 0d740c30c84..dcd9b38fab8 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store.cpp
@@ -5,14 +5,6 @@
namespace vespalib::datastore {
-template class BufferType<UniqueStoreEntry<int8_t>>;
-template class BufferType<UniqueStoreEntry<int16_t>>;
-template class BufferType<UniqueStoreEntry<int32_t>>;
-template class BufferType<UniqueStoreEntry<int64_t>>;
-template class BufferType<UniqueStoreEntry<uint32_t>>;
-template class BufferType<UniqueStoreEntry<float>>;
-template class BufferType<UniqueStoreEntry<double>>;
-
using namespace btree;
VESPALIB_DATASTORE_INSTANTIATE_BUFFERTYPE_INTERNALNODE(EntryRef, NoAggregated, uniquestore::DefaultDictionaryTraits::INTERNAL_SLOTS);
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.h b/vespalib/src/vespa/vespalib/datastore/unique_store.h
index aea98f406e8..281b719deea 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store.h
@@ -13,6 +13,8 @@
#include "unique_store_comparator.h"
#include "unique_store_entry.h"
+namespace vespalib::alloc { class MemoryAllocator; }
+
namespace vespalib::datastore {
template <typename Allocator>
@@ -47,8 +49,8 @@ private:
using generation_t = vespalib::GenerationHandler::generation_t;
public:
- UniqueStore();
- UniqueStore(std::unique_ptr<IUniqueStoreDictionary> dict);
+ UniqueStore(std::shared_ptr<alloc::MemoryAllocator> memory_allocator);
+ UniqueStore(std::shared_ptr<alloc::MemoryAllocator> memory_allocator, std::unique_ptr<IUniqueStoreDictionary> dict);
~UniqueStore();
void set_dictionary(std::unique_ptr<IUniqueStoreDictionary> dict);
UniqueStoreAddResult add(EntryConstRefType value);
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
index b73b714a6bc..06a2f288673 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store.hpp
@@ -27,14 +27,14 @@ using DefaultUniqueStoreDictionary = UniqueStoreDictionary<DefaultDictionary>;
}
template <typename EntryT, typename RefT, typename Compare, typename Allocator>
-UniqueStore<EntryT, RefT, Compare, Allocator>::UniqueStore()
- : UniqueStore<EntryT, RefT, Compare, Allocator>(std::make_unique<uniquestore::DefaultUniqueStoreDictionary>(std::unique_ptr<EntryComparator>()))
+UniqueStore<EntryT, RefT, Compare, Allocator>::UniqueStore(std::shared_ptr<alloc::MemoryAllocator> memory_allocator)
+ : UniqueStore<EntryT, RefT, Compare, Allocator>(std::move(memory_allocator), std::make_unique<uniquestore::DefaultUniqueStoreDictionary>(std::unique_ptr<EntryComparator>()))
{
}
template <typename EntryT, typename RefT, typename Compare, typename Allocator>
-UniqueStore<EntryT, RefT, Compare, Allocator>::UniqueStore(std::unique_ptr<IUniqueStoreDictionary> dict)
- : _allocator(),
+UniqueStore<EntryT, RefT, Compare, Allocator>::UniqueStore(std::shared_ptr<alloc::MemoryAllocator> memory_allocator, std::unique_ptr<IUniqueStoreDictionary> dict)
+ : _allocator(std::move(memory_allocator)),
_store(_allocator.get_data_store()),
_dict(std::move(dict))
{
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.h
index 0648f466bae..025165ee0e0 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.h
@@ -5,9 +5,12 @@
#include "datastore.h"
#include "entryref.h"
#include "unique_store_add_result.h"
+#include "unique_store_buffer_type.h"
#include "unique_store_entry.h"
#include "i_compactable.h"
+namespace vespalib::alloc { class MemoryAllocator; }
+
namespace vespalib::datastore {
/**
@@ -23,13 +26,12 @@ public:
using EntryConstRefType = const EntryType &;
using WrappedEntryType = UniqueStoreEntry<EntryType>;
using RefType = RefT;
- using UniqueStoreBufferType = BufferType<WrappedEntryType>;
private:
DataStoreType _store;
- UniqueStoreBufferType _typeHandler;
+ UniqueStoreBufferType<WrappedEntryType> _typeHandler;
public:
- UniqueStoreAllocator();
+ UniqueStoreAllocator(std::shared_ptr<alloc::MemoryAllocator> memory_allocator);
~UniqueStoreAllocator() override;
EntryRef allocate(const EntryType& value);
void hold(EntryRef ref);
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.hpp
index eb634503c9d..04a229d4ffa 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_allocator.hpp
@@ -3,6 +3,7 @@
#pragma once
#include "unique_store_allocator.h"
+#include "unique_store_buffer_type.hpp"
#include "unique_store_value_filter.h"
#include "datastore.hpp"
#include <vespa/vespalib/util/size_literals.h>
@@ -13,10 +14,10 @@ constexpr size_t NUM_ARRAYS_FOR_NEW_UNIQUESTORE_BUFFER = 1_Ki;
constexpr float ALLOC_GROW_FACTOR = 0.2;
template <typename EntryT, typename RefT>
-UniqueStoreAllocator<EntryT, RefT>::UniqueStoreAllocator()
+UniqueStoreAllocator<EntryT, RefT>::UniqueStoreAllocator(std::shared_ptr<alloc::MemoryAllocator> memory_allocator)
: ICompactable(),
_store(),
- _typeHandler(1, 2u, RefT::offsetSize(), NUM_ARRAYS_FOR_NEW_UNIQUESTORE_BUFFER, ALLOC_GROW_FACTOR)
+ _typeHandler(2u, RefT::offsetSize(), NUM_ARRAYS_FOR_NEW_UNIQUESTORE_BUFFER, ALLOC_GROW_FACTOR, std::move(memory_allocator))
{
auto typeId = _store.addType(&_typeHandler);
assert(typeId == 0u);
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.cpp b/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.cpp
new file mode 100644
index 00000000000..3441a9435a1
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.cpp
@@ -0,0 +1,25 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#include "unique_store_buffer_type.hpp"
+#include "unique_store_entry.h"
+
+namespace vespalib::datastore {
+
+template class BufferType<UniqueStoreEntry<int8_t>>;
+template class BufferType<UniqueStoreEntry<int16_t>>;
+template class BufferType<UniqueStoreEntry<int32_t>>;
+template class BufferType<UniqueStoreEntry<int64_t>>;
+template class BufferType<UniqueStoreEntry<uint32_t>>;
+template class BufferType<UniqueStoreEntry<float>>;
+template class BufferType<UniqueStoreEntry<double>>;
+
+template class UniqueStoreBufferType<UniqueStoreEntry<int8_t>>;
+template class UniqueStoreBufferType<UniqueStoreEntry<int16_t>>;
+template class UniqueStoreBufferType<UniqueStoreEntry<int32_t>>;
+template class UniqueStoreBufferType<UniqueStoreEntry<int64_t>>;
+template class UniqueStoreBufferType<UniqueStoreEntry<uint32_t>>;
+template class UniqueStoreBufferType<UniqueStoreEntry<float>>;
+template class UniqueStoreBufferType<UniqueStoreEntry<double>>;
+
+};
+
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.h b/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.h
new file mode 100644
index 00000000000..e6b531a6d0d
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.h
@@ -0,0 +1,27 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "buffer_type.h"
+#include <memory>
+
+namespace vespalib::alloc { class MemoryAllocator; }
+
+namespace vespalib::datastore {
+
+/*
+ * Class representing buffer type for a normal unique store allocator.
+ */
+template <typename WrappedEntry>
+class UniqueStoreBufferType : public BufferType<WrappedEntry>
+{
+ std::shared_ptr<alloc::MemoryAllocator> _memory_allocator;
+public:
+ UniqueStoreBufferType(uint32_t min_arrays, uint32_t max_arrays,
+ uint32_t num_arrays_for_new_buffer, float alloc_grow_factor,
+ std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept;
+ ~UniqueStoreBufferType();
+ const vespalib::alloc::MemoryAllocator* get_memory_allocator() const override;
+};
+
+}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.hpp
new file mode 100644
index 00000000000..c99033106ee
--- /dev/null
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_buffer_type.hpp
@@ -0,0 +1,29 @@
+// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+#pragma once
+
+#include "unique_store_buffer_type.h"
+#include "buffer_type.hpp"
+
+namespace vespalib::datastore {
+
+template <typename WrappedEntry>
+UniqueStoreBufferType<WrappedEntry>::UniqueStoreBufferType(uint32_t min_arrays, uint32_t max_arrays,
+ uint32_t num_arrays_for_new_buffer, float alloc_grow_factor,
+ std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept
+ : BufferType<WrappedEntry>(1u, min_arrays, max_arrays, num_arrays_for_new_buffer, alloc_grow_factor),
+ _memory_allocator(std::move(memory_allocator))
+{
+}
+
+template <typename WrappedEntry>
+UniqueStoreBufferType<WrappedEntry>::~UniqueStoreBufferType() = default;
+
+template <typename WrappedEntry>
+const vespalib::alloc::MemoryAllocator*
+UniqueStoreBufferType<WrappedEntry>::get_memory_allocator() const
+{
+ return _memory_allocator.get();
+}
+
+}
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.cpp b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.cpp
index 664f1e4432e..9c639067615 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.cpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.cpp
@@ -33,8 +33,9 @@ get_type_id(size_t string_len)
}
-UniqueStoreSmallStringBufferType::UniqueStoreSmallStringBufferType(uint32_t array_size, uint32_t max_arrays)
- : BufferType<char>(array_size, 2u, max_arrays, NUM_ARRAYS_FOR_NEW_UNIQUESTORE_BUFFER, ALLOC_GROW_FACTOR)
+UniqueStoreSmallStringBufferType::UniqueStoreSmallStringBufferType(uint32_t array_size, uint32_t max_arrays, std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator)
+ : BufferType<char>(array_size, 2u, max_arrays, NUM_ARRAYS_FOR_NEW_UNIQUESTORE_BUFFER, ALLOC_GROW_FACTOR),
+ _memory_allocator(std::move(memory_allocator))
{
}
@@ -68,8 +69,15 @@ UniqueStoreSmallStringBufferType::cleanHold(void *buffer, size_t offset, ElemCou
assert(e == e_end);
}
-UniqueStoreExternalStringBufferType::UniqueStoreExternalStringBufferType(uint32_t array_size, uint32_t max_arrays)
- : BufferType<UniqueStoreEntry<std::string>>(array_size, 2u, max_arrays, NUM_ARRAYS_FOR_NEW_UNIQUESTORE_BUFFER, ALLOC_GROW_FACTOR)
+const vespalib::alloc::MemoryAllocator*
+UniqueStoreSmallStringBufferType::get_memory_allocator() const
+{
+ return _memory_allocator.get();
+}
+
+UniqueStoreExternalStringBufferType::UniqueStoreExternalStringBufferType(uint32_t array_size, uint32_t max_arrays, std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator)
+ : BufferType<UniqueStoreEntry<std::string>>(array_size, 2u, max_arrays, NUM_ARRAYS_FOR_NEW_UNIQUESTORE_BUFFER, ALLOC_GROW_FACTOR),
+ _memory_allocator(std::move(memory_allocator))
{
}
@@ -86,6 +94,12 @@ UniqueStoreExternalStringBufferType::cleanHold(void *buffer, size_t offset, Elem
}
}
+const vespalib::alloc::MemoryAllocator*
+UniqueStoreExternalStringBufferType::get_memory_allocator() const
+{
+ return _memory_allocator.get();
+}
+
template class UniqueStoreStringAllocator<EntryRefT<22>>;
template class BufferType<UniqueStoreEntry<std::string>>;
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h
index 7b4c578f248..be5fa8f6c1e 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.h
@@ -10,6 +10,8 @@
#include <cassert>
#include <string>
+namespace vespalib::alloc { class MemoryAllocator; }
+
namespace vespalib::datastore {
namespace string_allocator {
@@ -56,22 +58,26 @@ public:
* bytes
*/
class UniqueStoreSmallStringBufferType : public BufferType<char> {
+ std::shared_ptr<vespalib::alloc::MemoryAllocator> _memory_allocator;
public:
- UniqueStoreSmallStringBufferType(uint32_t array_size, uint32_t max_arrays);
+ UniqueStoreSmallStringBufferType(uint32_t array_size, uint32_t max_arrays, std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator);
~UniqueStoreSmallStringBufferType() override;
void destroyElements(void *, ElemCount) override;
void fallbackCopy(void *newBuffer, const void *oldBuffer, ElemCount numElems) override;
void cleanHold(void *buffer, size_t offset, ElemCount numElems, CleanContext) override;
+ const vespalib::alloc::MemoryAllocator* get_memory_allocator() const override;
};
/*
* Buffer type for external strings in unique store.
*/
class UniqueStoreExternalStringBufferType : public BufferType<UniqueStoreEntry<std::string>> {
+ std::shared_ptr<vespalib::alloc::MemoryAllocator> _memory_allocator;
public:
- UniqueStoreExternalStringBufferType(uint32_t array_size, uint32_t max_arrays);
+ UniqueStoreExternalStringBufferType(uint32_t array_size, uint32_t max_arrays, std::shared_ptr<vespalib::alloc::MemoryAllocator> memory_allocator);
~UniqueStoreExternalStringBufferType() override;
void cleanHold(void *buffer, size_t offset, ElemCount numElems, CleanContext cleanCtx) override;
+ const vespalib::alloc::MemoryAllocator* get_memory_allocator() const override;
};
/**
@@ -101,7 +107,7 @@ private:
static uint32_t get_type_id(const char *value);
public:
- UniqueStoreStringAllocator();
+ UniqueStoreStringAllocator(std::shared_ptr<alloc::MemoryAllocator> memory_allocator);
~UniqueStoreStringAllocator() override;
EntryRef allocate(const char *value);
void hold(EntryRef ref);
diff --git a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.hpp b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.hpp
index 90c44200fbb..71ea16bcde2 100644
--- a/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.hpp
+++ b/vespalib/src/vespa/vespalib/datastore/unique_store_string_allocator.hpp
@@ -8,14 +8,14 @@
namespace vespalib::datastore {
template <typename RefT>
-UniqueStoreStringAllocator<RefT>::UniqueStoreStringAllocator()
+UniqueStoreStringAllocator<RefT>::UniqueStoreStringAllocator(std::shared_ptr<alloc::MemoryAllocator> memory_allocator)
: ICompactable(),
_store(),
_type_handlers()
{
- _type_handlers.emplace_back(std::make_unique<UniqueStoreExternalStringBufferType>(1, RefT::offsetSize()));
+ _type_handlers.emplace_back(std::make_unique<UniqueStoreExternalStringBufferType>(1, RefT::offsetSize(), memory_allocator));
for (auto size : string_allocator::array_sizes) {
- _type_handlers.emplace_back(std::make_unique<UniqueStoreSmallStringBufferType>(size, RefT::offsetSize()));
+ _type_handlers.emplace_back(std::make_unique<UniqueStoreSmallStringBufferType>(size, RefT::offsetSize(), memory_allocator));
}
uint32_t exp_type_id = 0;
for (auto &type_handler : _type_handlers) {