1#pragma once
2
3#include <cstdlib>
4#include <utility>
5#include <boost/noncopyable.hpp>
6
7
8namespace DB
9{
10
11/** Aligned piece of memory.
12 * It can only be allocated and destroyed.
13 * MemoryTracker is not used. AlignedBuffer is intended for small pieces of memory.
14 */
15class AlignedBuffer : private boost::noncopyable
16{
17private:
18 void * buf = nullptr;
19
20 void alloc(size_t size, size_t alignment);
21 void dealloc();
22
23public:
24 AlignedBuffer() {}
25 AlignedBuffer(size_t size, size_t alignment);
26 AlignedBuffer(AlignedBuffer && old) { std::swap(buf, old.buf); }
27 ~AlignedBuffer();
28
29 void reset(size_t size, size_t alignment);
30
31 char * data() { return static_cast<char *>(buf); }
32 const char * data() const { return static_cast<const char *>(buf); }
33};
34
35}
36
37