Kùzu C++ API
Loading...
Searching...
No Matches
in_mem_overflow_buffer.h
Go to the documentation of this file.
1#pragma once
2
3#include <iterator>
4#include <memory>
5#include <vector>
6
7namespace kuzu {
8namespace storage {
9class MemoryBuffer;
10class MemoryManager;
11} // namespace storage
12
13namespace common {
14
16public:
17 explicit BufferBlock(std::unique_ptr<storage::MemoryBuffer> block);
19
20 uint64_t size() const;
21 uint8_t* data() const;
22
23public:
24 uint64_t currentOffset;
25 std::unique_ptr<storage::MemoryBuffer> block;
26
28};
29
31
32public:
33 explicit InMemOverflowBuffer(storage::MemoryManager* memoryManager)
34 : memoryManager{memoryManager}, currentBlock{nullptr} {};
35
36 uint8_t* allocateSpace(uint64_t size);
37
39 move(begin(other.blocks), end(other.blocks), back_inserter(blocks));
40 // We clear the other InMemOverflowBuffer's block because when it is deconstructed,
41 // InMemOverflowBuffer's deconstructed tries to free these pages by calling
42 // memoryManager->freeBlock, but it should not because this InMemOverflowBuffer still
43 // needs them.
44 other.blocks.clear();
45 currentBlock = other.currentBlock;
46 }
47
48 // Releases all memory accumulated for string overflows so far and re-initializes its state to
49 // an empty buffer. If there is a large string that used point to any of these overflow buffers
50 // they will error.
52
53private:
54 bool requireNewBlock(uint64_t sizeToAllocate) {
55 return currentBlock == nullptr ||
56 (currentBlock->currentOffset + sizeToAllocate) > currentBlock->size();
57 }
58
59 void allocateNewBlock(uint64_t size);
60
61private:
62 std::vector<std::unique_ptr<BufferBlock>> blocks;
63 storage::MemoryManager* memoryManager;
64 BufferBlock* currentBlock;
65};
66
67} // namespace common
68} // namespace kuzu
Definition in_mem_overflow_buffer.h:30
void merge(InMemOverflowBuffer &other)
Definition in_mem_overflow_buffer.h:38
uint8_t * allocateSpace(uint64_t size)
InMemOverflowBuffer(storage::MemoryManager *memoryManager)
Definition in_mem_overflow_buffer.h:33
Definition array_utils.h:7
Definition in_mem_overflow_buffer.h:15
uint64_t currentOffset
Definition in_mem_overflow_buffer.h:24
std::unique_ptr< storage::MemoryBuffer > block
Definition in_mem_overflow_buffer.h:25
uint8_t * data() const
void resetCurrentOffset()
Definition in_mem_overflow_buffer.h:27
BufferBlock(std::unique_ptr< storage::MemoryBuffer > block)
uint64_t size() const