-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalloc.cpp
More file actions
56 lines (55 loc) · 905 Bytes
/
alloc.cpp
File metadata and controls
56 lines (55 loc) · 905 Bytes
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "alloc.hpp"
void alloc::allocate(size_t size)
{
this->size = size;
data = new uint8_t[size];
}
void alloc::deallocate()
{
if (data)
delete[] data;
}
void alloc::destroy()
{
if (dtor && data)
dtor(data);
}
alloc::alloc(size_t size)
{
allocate(size);
}
bool alloc::operator==(const alloc &other) const noexcept
{
return data == other.data;
}
alloc::~alloc()
{
destroy();
deallocate();
}
alloc::alloc(alloc &&other) noexcept
{
if (this == &other)
return;
alive = other.alive;
data = other.data;
size = other.size;
dtor = other.dtor;
other.data = nullptr;
other.size = 0;
other.dtor = nullptr;
}
const alloc &alloc::operator=(alloc &&other) noexcept
{
if (this == &other)
return *this;
deallocate(), destroy();
alive = other.alive;
data = other.data;
size = other.size;
dtor = other.dtor;
other.data = nullptr;
other.size = 0;
other.dtor = nullptr;
return *this;
}