aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/datastore/raw_allocator.h
blob: fea454ba0f03f392c16f2e407ad6068e3547f620 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "datastorebase.h"
#include "entryref.h"
#include "handle.h"

namespace vespalib::datastore {

/**
 * Allocator used to allocate raw buffers (EntryT *) in an underlying data store
 * with no construction or de-construction of elements in the buffer.
 */
template <typename EntryT, typename RefT>
class RawAllocator
{
public:
    using HandleType = Handle<EntryT>;

protected:
    DataStoreBase &_store;
    uint32_t _typeId;

public:
    RawAllocator(DataStoreBase &store, uint32_t typeId);

    HandleType alloc(size_t num_entries) {
        return alloc(num_entries, 0);
    }
    HandleType alloc(size_t num_entries, size_t extra_entries);
    template <typename BufferType>
    HandleType alloc_dynamic_array(size_t array_size);
};

}