IsoSpec 2.2.1
Loading...
Searching...
No Matches
allocator.cpp
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
18#include "allocator.h"
19
20namespace IsoSpec
21{
22
23template <typename T>
24Allocator<T>::Allocator(const int dim_, const int tabSize_): currentTab(new T[dim_ * tabSize_]), currentId(-1), dim(dim_), tabSize(tabSize_) {}
25
26
27template <typename T>
29{
30 if(prevTabs.size() == 0 || currentTab != prevTabs.back())
31 {
32 // It will be equal only if shiftTables throws during new[]
33 // Make sure we don't del currentTab twice in that case
34 delete [] currentTab;
35 }
36
37 for(unsigned int i = 0; i < prevTabs.size(); ++i)
38 delete [] prevTabs[i];
39}
40
41template <typename T>
43{
44 prevTabs.push_back(currentTab);
45 currentTab = new T[dim * tabSize];
46 currentId = 0;
47}
48
49template class Allocator<int>;
50
51} // namespace IsoSpec