forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpallocator.h
More file actions
106 lines (86 loc) · 3.5 KB
/
pallocator.h
File metadata and controls
106 lines (86 loc) · 3.5 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* PANDA 3D SOFTWARE
* Copyright (c) Carnegie Mellon University. All rights reserved.
*
* All use of this software is subject to the terms of the revised BSD
* license. You should have received a copy of this license along
* with this source code in a file named "LICENSE."
*
* @file pallocator.h
* @author drose
* @date 2001-06-05
*/
#ifndef PALLOCATOR_H
#define PALLOCATOR_H
#include <memory>
#include "dtoolbase.h"
#include "memoryHook.h"
#include "deletedChain.h"
#include "typeHandle.h"
/**
* This is our own Panda specialization on the default STL allocator. Its
* main purpose is to call the hooks for MemoryUsage to properly track STL-
* allocated memory.
*
* pvector, pmap, etc. are all defined in this directory to use a pallocator.
*
* pallocator actually comes it two flavors now: pallocator_single, which can
* only allocate single instances of an object, and pallocator_array, which
* can allocate arrays of objects.
*/
#if !defined(USE_STL_ALLOCATOR) || defined(CPPPARSER)
// If we're not trying to make custom allocators (either we don't know what
// kind of syntax this STL library wants, or we're compiling with OPTIMIZE 4),
// then simply use the standard allocator.
#define pallocator_single std::allocator
#define pallocator_array std::allocator
#else
template<class Type>
class pallocator_single : public std::allocator<Type> {
public:
// Nowadays we cannot implicitly inherit typedefs from base classes in a
// template class; we must explicitly copy them here.
typedef typename std::allocator<Type>::pointer pointer;
typedef typename std::allocator<Type>::reference reference;
typedef typename std::allocator<Type>::const_pointer const_pointer;
typedef typename std::allocator<Type>::const_reference const_reference;
typedef typename std::allocator<Type>::size_type size_type;
INLINE pallocator_single(TypeHandle type_handle) noexcept;
// template member functions in VC++ can only be defined in-class.
template<class U>
INLINE pallocator_single(const pallocator_single<U> ©) noexcept :
_type_handle(copy._type_handle) { }
INLINE Type *allocate(size_type n, std::allocator<void>::const_pointer hint = 0)
RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT);
INLINE void deallocate(pointer p, size_type n);
template<class U> struct rebind {
typedef pallocator_single<U> other;
};
TypeHandle _type_handle;
};
template<class Type>
class pallocator_array : public std::allocator<Type> {
public:
// Nowadays we cannot implicitly inherit typedefs from base classes in a
// template class; we must explicitly copy them here.
typedef typename std::allocator<Type>::pointer pointer;
typedef typename std::allocator<Type>::reference reference;
typedef typename std::allocator<Type>::const_pointer const_pointer;
typedef typename std::allocator<Type>::const_reference const_reference;
typedef typename std::allocator<Type>::size_type size_type;
INLINE pallocator_array(TypeHandle type_handle = TypeHandle::none()) noexcept;
// template member functions in VC++ can only be defined in-class.
template<class U>
INLINE pallocator_array(const pallocator_array<U> ©) noexcept :
_type_handle(copy._type_handle) { }
INLINE Type *allocate(size_type n, std::allocator<void>::const_pointer hint = 0)
RETURNS_ALIGNED(MEMORY_HOOK_ALIGNMENT);
INLINE void deallocate(pointer p, size_type n);
template<class U> struct rebind {
typedef pallocator_array<U> other;
};
TypeHandle _type_handle;
};
#include "pallocator.T"
#endif // USE_STL_ALLOCATOR
#endif