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} {};
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 }
51
52 // Releases all memory accumulated for string overflows so far and re-initializes its state to
53 // an empty buffer. If there is a large string that used point to any of these overflow buffers
54 // they will error.
56
57 storage::MemoryManager* getMemoryManager() { return memoryManager; }
58
59private:
60 bool requireNewBlock(uint64_t sizeToAllocate) {
61 return blocks.empty() ||
62 (currentBlock()->currentOffset + sizeToAllocate) > currentBlock()->size();
63 }
64
65 void allocateNewBlock(uint64_t size);
66
67 BufferBlock* currentBlock() { return blocks.back().get(); }
68
69private:
70 std::vector<std::unique_ptr<BufferBlock>> blocks;
71 storage::MemoryManager* memoryManager;
72};
73
74} // namespace common
75} // namespace kuzu
#define KUZU_API
Definition api.h:25
void merge(InMemOverflowBuffer &other)
Definition in_mem_overflow_buffer.h:43
DEFAULT_BOTH_MOVE(InMemOverflowBuffer)
storage::MemoryManager * getMemoryManager()
Definition in_mem_overflow_buffer.h:57
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
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