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
56
57
58
59
/*
* Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
*
* This file is part of IsoSpec.
*
* IsoSpec is free software: you can redistribute it and/or modify
* it under the terms of the Simplified ("2-clause") BSD licence.
*
* IsoSpec is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the Simplified BSD Licence
* along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
*/
#pragma once
#include <cstring>
#include "pod_vector.h"
#include "allocator.h"
namespace IsoSpec
{
class DirtyAllocator
{
private:
void* currentTab;
void* currentConf;
void* endOfTablePtr;
const int tabSize;
int cellSize;
pod_vector<void*> prevTabs;
public:
explicit DirtyAllocator(const int dim, const int tabSize = default_tab_size);
~DirtyAllocator();
DirtyAllocator(const DirtyAllocator& other) = delete;
DirtyAllocator& operator=(const DirtyAllocator& other) = delete;
void shiftTables();
inline void* newConf()
{
if (currentConf >= endOfTablePtr)
{
shiftTables();
}
void* ret = currentConf;
currentConf = reinterpret_cast<char*>(currentConf) + cellSize;
return ret;
}
};
} // namespace IsoSpec