aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/large_array_buffer_type.hpp
blob: 72a2662991b57d88786107b51d41837ea72f9a64 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "large_array_buffer_type.h"
#include <vespa/vespalib/util/array.hpp>

namespace vespalib::datastore {

template <typename ElemT>
LargeArrayBufferType<ElemT>::LargeArrayBufferType(const AllocSpec& spec, std::shared_ptr<alloc::MemoryAllocator> memory_allocator) noexcept
    : BufferType<Array<ElemT>>(1u, spec.min_entries_in_buffer, spec.max_entries_in_buffer, spec.num_entries_for_new_buffer, spec.allocGrowFactor),
      _memory_allocator(std::move(memory_allocator))
{
}

template <typename ElemT>
LargeArrayBufferType<ElemT>::~LargeArrayBufferType() = default;

template <typename ElemT>
void
LargeArrayBufferType<ElemT>::clean_hold(void* buffer, size_t offset, EntryCount num_entries, CleanContext cleanCtx)
{
    ArrayType* elem = static_cast<ArrayType*>(buffer) + offset;
    const auto& empty = empty_entry();
    for (size_t i = 0; i < num_entries; ++i) {
        cleanCtx.extraBytesCleaned(sizeof(ElemT) * elem->size());
        *elem = empty;
        ++elem;
    }
}

template <typename ElemT>
const vespalib::alloc::MemoryAllocator*
LargeArrayBufferType<ElemT>::get_memory_allocator() const
{
    return _memory_allocator.get();
}

}