aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.h
blob: cf472b7a642e3de845d4c2d1fd70f24c8a870717 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "array_store_config.h"
#include "buffer_type.h"
#include <vespa/vespalib/util/array.h>
#include <memory>

namespace vespalib::alloc { class MemoryAllocator; }

namespace vespalib::datastore {

/*
 * Class representing buffer type for large arrays in ArrayStore
 */
template <typename ElemT>
class LargeArrayBufferType : public BufferType<Array<ElemT>>
{
    using AllocSpec = ArrayStoreConfig::AllocSpec;
    using ArrayType = Array<ElemT>;
    using ParentType = BufferType<ArrayType>;
    using ParentType::empty_entry;
    using CleanContext = typename ParentType::CleanContext;
    std::shared_ptr<alloc::MemoryAllocator> _memory_allocator;
public:
    LargeArrayBufferType(const AllocSpec& spec, std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept;
    template <typename TypeMapper>
    LargeArrayBufferType(const AllocSpec& spec, std::shared_ptr<alloc::MemoryAllocator> memory_allocator, TypeMapper&) noexcept
        : LargeArrayBufferType(spec, std::move(memory_allocator))
    {
    }
    ~LargeArrayBufferType() override;
    void clean_hold(void* buffer, size_t offset, EntryCount num_entries, CleanContext cleanCtx) override;
    const vespalib::alloc::MemoryAllocator* get_memory_allocator() const override;
    alloc::Alloc initial_alloc() const noexcept {
        return _memory_allocator ? alloc::Alloc::alloc_with_allocator(_memory_allocator.get()) : alloc::Alloc::alloc(0, alloc::MemoryAllocator::HUGEPAGE_SIZE);
    }
};

extern template class LargeArrayBufferType<uint8_t>;
extern template class LargeArrayBufferType<uint32_t>;
extern template class LargeArrayBufferType<int32_t>;
extern template class LargeArrayBufferType<std::string>;
extern template class LargeArrayBufferType<AtomicEntryRef>;

}