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