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