IsoSpec  2.1.2
dirtyAllocator.h
1 /*
2  * Copyright (C) 2015-2020 Mateusz Łącki and Michał Startek.
3  *
4  * This file is part of IsoSpec.
5  *
6  * IsoSpec is free software: you can redistribute it and/or modify
7  * it under the terms of the Simplified ("2-clause") BSD licence.
8  *
9  * IsoSpec is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12  *
13  * You should have received a copy of the Simplified BSD Licence
14  * along with IsoSpec. If not, see <https://opensource.org/licenses/BSD-2-Clause>.
15  */
16 
17 #pragma once
18 
19 #include <cstring>
20 #include "pod_vector.h"
21 
22 namespace IsoSpec
23 {
24 
26 {
27  private:
28  void* currentTab;
29  void* currentConf;
30  void* endOfTablePtr;
31  const int tabSize;
32  int cellSize;
33  pod_vector<void*> prevTabs;
34 
35  public:
36  explicit DirtyAllocator(const int dim, const int tabSize = 10000);
37  ~DirtyAllocator();
38 
39  DirtyAllocator(const DirtyAllocator& other) = delete;
40  DirtyAllocator& operator=(const DirtyAllocator& other) = delete;
41 
42  void shiftTables();
43 
44  inline void* newConf()
45  {
46  if (currentConf >= endOfTablePtr)
47  {
48  shiftTables();
49  }
50 
51  void* ret = currentConf;
52  currentConf = reinterpret_cast<char*>(currentConf) + cellSize;
53 
54  return ret;
55  }
56 };
57 
58 } // namespace IsoSpec
pod_vector< void * >
IsoSpec
Definition: allocator.cpp:20
IsoSpec::DirtyAllocator
Definition: dirtyAllocator.h:25