forked from tuxalin/THST
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallocator.h
46 lines (34 loc) · 985 Bytes
/
allocator.h
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
//
// allocator.h
//
//
#pragma once
#include "config.h"
#if SPATIAL_TREE_ALLOCATOR == SPATIAL_TREE_DEFAULT_ALLOCATOR
#include <assert.h>
#include <stdint.h>
#elif SPATIAL_TREE_ALLOCATOR == SPATIAL_TREE_STD_ALLOCATOR
#include <memory>
#endif
namespace spatial {
#if SPATIAL_TREE_ALLOCATOR == SPATIAL_TREE_DEFAULT_ALLOCATOR
/// A simplified heap allocator.
template <class NodeClass> struct allocator {
typedef NodeClass value_type;
/// @note If true then overflow checks will be performed.
enum { is_overflowable = 0 };
value_type *allocate(int level) { return new NodeClass(level); }
void deallocate(const value_type *node) {
assert(node);
delete node;
}
/// If true then an overflowed has occurred.
/// @note Only used if is_overflowable is true.
bool overflowed() const { return false; }
};
#elif SPATIAL_TREE_ALLOCATOR == SPATIAL_TREE_STD_ALLOCATOR
using std::allocator;
#else
#error "Unknown allocator type!"
#endif
} // namespace spatial