MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
vector_buffer.h
1#pragma once
2
3#include "storage/common/arena_allocator.h"
4#include "common/type/string_t.h"
5#include "common/log/log.h"
6
8{
9public:
10 VectorBuffer() = default;
11
12 string_t add_string(const char *data, int len)
13 {
14 if (len <= string_t::INLINE_LENGTH) {
15 return string_t(data, len);
16 }
17 auto insert_string = empty_string(len);
18 auto insert_pos = insert_string.get_data_writeable();
19 memcpy(insert_pos, data, len);
20 return insert_string;
21 }
22
23 string_t add_string(string_t data) { return add_string(data.data(), data.size()); }
24
25 string_t empty_string(int len)
26 {
27 ASSERT(len > string_t::INLINE_LENGTH, "len > string_t::INLINE_LENGTH");
28 auto insert_pos = heap.Allocate(len);
29 return string_t(insert_pos, len);
30 }
31
32private:
33 Arena heap;
34};
Definition: arena_allocator.h:24
Definition: vector_buffer.h:8
Definition: string_t.h:18