forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeletedChain.T
More file actions
145 lines (129 loc) · 4.2 KB
/
deletedChain.T
File metadata and controls
145 lines (129 loc) · 4.2 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* 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 deletedChain.T
* @author drose
* @date 2006-04-01
*/
template<class Type>
DeletedChain<Type> StaticDeletedChain<Type>::_chain;
/**
* Allocates the memory for a new object of Type.
*/
template<class Type>
INLINE Type *DeletedChain<Type>::
allocate(size_t size, TypeHandle type_handle) {
TAU_PROFILE("Type *DeletedChain<Type>::allocate(size_t, TypeHandle)", " ", TAU_USER);
init_deleted_chain();
void *ptr = _chain->allocate(size, type_handle);
#ifdef DO_MEMORY_USAGE
memory_hook->mark_pointer(ptr, _chain->get_buffer_size(), make_ref_ptr(ptr));
#endif // DO_MEMORY_USAGE
return (Type *)ASSUME_ALIGNED(ptr, MEMORY_HOOK_ALIGNMENT);
}
/**
* Frees the memory for an object of Type.
*/
template<class Type>
INLINE void DeletedChain<Type>::
deallocate(Type *ptr, TypeHandle type_handle) {
TAU_PROFILE("void DeletedChain<Type>::deallocate(Type *, TypeHandle)", " ", TAU_USER);
#ifdef DO_MEMORY_USAGE
memory_hook->mark_pointer(ptr, 0, make_ref_ptr(ptr));
#endif
// We have to call this again, even though it must have been called
// in allocate(), because with template resolution across dll's it
// is possible that this DeletedChain object is not the same one
// that allocated the object.
init_deleted_chain();
_chain->deallocate(ptr, type_handle);
}
/**
* Returns true if the pointer is valid, false if it has been deleted or if it
* was never a valid pointer.
*
* This is only meaningful in debug mode, where USE_DELETEDCHAINFLAG is
* defined. If not, this trivially returns true.
*/
template<class Type>
INLINE bool DeletedChain<Type>::
validate(const Type *ptr) {
TAU_PROFILE("bool DeletedChain<Type>::validate(Type *)", " ", TAU_USER);
#ifdef USE_DELETEDCHAINFLAG
init_deleted_chain();
return _chain->validate((void *)ptr);
#else
return true;
#endif // USE_DELETEDCHAINFLAG
}
/**
* This method has two overloads: one that accepts a void *, and one that
* accepts a ReferenceCount *. We rely on the C++ compiler to select the most
* appropriate one for a given type to return the ReferenceCount pointer that
* corresponds to a particular type, or NULL if the type does not inherit from
* ReferenceCount.
*/
template<class Type>
INLINE ReferenceCount *DeletedChain<Type>::
make_ref_ptr(void *) {
return NULL;
}
/**
* This method has two overloads: one that accepts a void *, and one that
* accepts a ReferenceCount *. We rely on the C++ compiler to select the most
* appropriate one for a given type to return the ReferenceCount pointer that
* corresponds to a particular type, or NULL if the type does not inherit from
* ReferenceCount.
*/
template<class Type>
INLINE ReferenceCount *DeletedChain<Type>::
make_ref_ptr(ReferenceCount *ptr) {
return ptr;
}
/**
* Assigns the _chain pointer if it is not already assigned. This can't be
* done by a constructor, since often the DeletedChain instance is used before
* its static construct has had a chance to be called.
*/
template<class Type>
void DeletedChain<Type>::
init_deleted_chain() {
if (_chain == (DeletedBufferChain *)NULL) {
init_memory_hook();
_chain = memory_hook->get_deleted_chain(sizeof(Type));
}
}
/**
* Allocates the memory for a new object of Type.
*/
template<class Type>
INLINE Type *StaticDeletedChain<Type>::
allocate(size_t size, TypeHandle type_handle) {
Type *ptr = _chain.allocate(size, type_handle);
return (Type *)ASSUME_ALIGNED(ptr, MEMORY_HOOK_ALIGNMENT);
}
/**
* Frees the memory for an object of Type.
*/
template<class Type>
INLINE void StaticDeletedChain<Type>::
deallocate(Type *ptr, TypeHandle type_handle) {
_chain.deallocate(ptr, type_handle);
}
/**
* Returns true if the pointer is valid, false if it has been deleted or if it
* was never a valid pointer.
*
* This is only meaningful in debug mode, where USE_DELETEDCHAINFLAG is
* defined. If not, this trivially returns true.
*/
template<class Type>
INLINE bool StaticDeletedChain<Type>::
validate(const Type *ptr) {
return _chain.validate(ptr);
}