00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef DELETEDCHAIN_H
00016 #define DELETEDCHAIN_H
00017
00018 #include "dtoolbase.h"
00019 #include "deletedBufferChain.h"
00020 #include <assert.h>
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 template<class Type>
00046 class DeletedChain {
00047 public:
00048 INLINE Type *allocate(size_t size, TypeHandle type_handle);
00049 INLINE void deallocate(Type *ptr, TypeHandle type_handle);
00050
00051 INLINE bool validate(const Type *ptr);
00052
00053 static INLINE ReferenceCount *make_ref_ptr(void *ptr);
00054 static INLINE ReferenceCount *make_ref_ptr(ReferenceCount *ptr);
00055
00056 private:
00057 INLINE void init_deleted_chain();
00058
00059 DeletedBufferChain *_chain;
00060 };
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 template<class Type>
00080 class StaticDeletedChain {
00081 public:
00082 INLINE static Type *allocate(size_t size, TypeHandle type_handle);
00083 INLINE static void deallocate(Type *ptr, TypeHandle type_handle);
00084
00085 INLINE static bool validate(const Type *ptr);
00086
00087 static DeletedChain<Type> _chain;
00088 };
00089
00090 #ifdef USE_DELETED_CHAIN
00091
00092
00093
00094 #define ALLOC_DELETED_CHAIN(Type) \
00095 inline void *operator new(size_t size) { \
00096 return (void *)StaticDeletedChain< Type >::allocate(size, get_type_handle(Type)); \
00097 } \
00098 inline void *operator new(size_t size, void *ptr) { \
00099 return ptr; \
00100 } \
00101 inline void operator delete(void *ptr) { \
00102 StaticDeletedChain< Type >::deallocate((Type *)ptr, get_type_handle(Type)); \
00103 } \
00104 inline void operator delete(void *, void *) { \
00105 } \
00106 inline static bool validate_ptr(const void *ptr) { \
00107 return StaticDeletedChain< Type >::validate((const Type *)ptr); \
00108 }
00109
00110
00111
00112
00113 #define ALLOC_DELETED_CHAIN_DECL(Type) \
00114 inline void *operator new(size_t size) { \
00115 return (void *)_deleted_chain.allocate(size, get_type_handle(Type)); \
00116 } \
00117 inline void *operator new(size_t size, void *ptr) { \
00118 return ptr; \
00119 } \
00120 inline void operator delete(void *ptr) { \
00121 _deleted_chain.deallocate((Type *)ptr, get_type_handle(Type)); \
00122 } \
00123 inline void operator delete(void *, void *) { \
00124 } \
00125 inline static bool validate_ptr(const void *ptr) { \
00126 return _deleted_chain.validate((const Type *)ptr); \
00127 } \
00128 static DeletedChain< Type > _deleted_chain;
00129
00130
00131
00132 #define ALLOC_DELETED_CHAIN_DEF(Type) \
00133 DeletedChain< Type > Type::_deleted_chain;
00134
00135 #else // USE_DELETED_CHAIN
00136
00137 #define ALLOC_DELETED_CHAIN(Type) \
00138 inline static bool validate_ptr(const void *ptr) { \
00139 return (ptr != NULL); \
00140 }
00141 #define ALLOC_DELETED_CHAIN_DECL(Type) \
00142 inline static bool validate_ptr(const void *ptr) { \
00143 return (ptr != NULL); \
00144 }
00145 #define ALLOC_DELETED_CHAIN_DEF(Type)
00146
00147 #endif // USE_DELETED_CHAIN
00148
00149 #include "deletedChain.T"
00150
00151 #endif
00152