29#ifndef PX_PROFILE_ALLOCATOR_WRAPPER_H
30#define PX_PROFILE_ALLOCATOR_WRAPPER_H
32#include "foundation/PxPreprocessor.h"
33#include "foundation/PxAllocatorCallback.h"
34#include "foundation/PxErrorCallback.h"
35#include "foundation/PxAssert.h"
36#include "foundation/PxHashMap.h"
37#include "foundation/PxArray.h"
39namespace physx {
namespace profile {
50 : mUserAllocator( &inUserAllocator )
55 : mUserAllocator( inUserAllocator )
61 PX_ASSERT( NULL != mUserAllocator );
62 return *mUserAllocator;
72 static const char* getName()
74#if PX_LINUX || PX_OSX || PX_EMSCRIPTEN || PX_SWITCH
75 return __PRETTY_FUNCTION__;
77 return typeid(T).name();
85 : mWrapper( inOther.mWrapper )
90 mWrapper = inOther.mWrapper;
94 void* allocate(
size_t size,
const char* filename,
int line)
99 return getAllocator().
allocate(size, getName(), filename, line);
101 return getAllocator().
allocate(size,
"<no allocation names in this config>", filename, line);
104 void deallocate(
void* ptr)
117 const char* mAllocationName;
119 : mWrapper( &inWrapper )
120 , mAllocationName( inAllocationName )
123 : mWrapper( inOther.mWrapper )
124 , mAllocationName( inOther.mAllocationName )
129 mWrapper = inOther.mWrapper;
130 mAllocationName = inOther.mAllocationName;
134 void* allocate(
size_t size,
const char* filename,
int line)
138 return getAllocator().
allocate(size, mAllocationName, filename, line);
140 void deallocate(
void* ptr)
169 template<
typename TKeyType,
typename TValueType,
typename THashType=PxHash<TKeyType> >
183 template<
typename TDataType>
184 inline TDataType* PxProfileAllocate(
PxAllocatorCallback* inAllocator,
const char* file,
int inLine )
188 TAllocator theAllocator( wrapper );
189 return reinterpret_cast<TDataType*
>( theAllocator.allocate(
sizeof( TDataType ), file, inLine ) );
195 template<
typename TDataType>
196 inline TDataType* PxProfileAllocate(
PxAllocatorCallback& inAllocator,
const char* file,
int inLine )
198 return PxProfileAllocate<TDataType>( &inAllocator, file, inLine );
204 template<
typename TDataType>
205 inline void PxProfileDeleteAndDeallocate( PxProfileAllocatorWrapper& inAllocator, TDataType* inDType )
208 PxAllocatorCallback& allocator( inAllocator.getAllocator() );
209 inDType->~TDataType();
210 allocator.deallocate( inDType );
216 template<
typename TDataType>
217 inline void PxProfileDeleteAndDeallocate( PxAllocatorCallback& inAllocator, TDataType* inDType )
219 PxProfileAllocatorWrapper wrapper( &inAllocator );
220 PxProfileDeleteAndDeallocate( wrapper, inDType );
225#define PX_PROFILE_NEW( allocator, dtype ) new (physx::profile::PxProfileAllocate<dtype>( allocator, __FILE__, __LINE__ )) dtype
226#define PX_PROFILE_DELETE( allocator, obj ) physx::profile::PxProfileDeleteAndDeallocate( allocator, obj );
Abstract base class for an application defined memory allocator that can be used by the Nv library.
Definition PxAllocatorCallback.h:53
virtual void deallocate(void *ptr)=0
Frees memory previously allocated by allocate().
virtual void * allocate(size_t size, const char *typeName, const char *filename, int line)=0
Allocates size bytes of memory, which must be 16-byte aligned.
Definition PxHashMap.h:78
Helper class to encapsulate the reflection allocator.
Definition PxProfileAllocatorWrapper.h:71
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Helper struct to encapsulate the user allocator callback Useful for array and hash templates.
Definition PxProfileAllocatorWrapper.h:46
Helper struct to encapsulate the array.
Definition PxProfileAllocatorWrapper.h:152
Helper struct to encapsulate the array.
Definition PxProfileAllocatorWrapper.h:171
Helper class to encapsulate the named allocator.
Definition PxProfileAllocatorWrapper.h:115