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