Main Page   Class List   Class Members  

  • Main Page
  • Modules
  • Classes
  • Files
  • File List

Allocator.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2017 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
00029 
00030 
00036 #pragma once
00037 
00038 #include <PsArray.h>
00039 #include <PsHashMap.h>
00040 #include <PsAlignedMalloc.h>
00041 #include "NvCloth/Callbacks.h"
00042 
00043 namespace nv
00044 {
00045 namespace cloth
00046 {
00047 
00048 void* allocate(size_t);
00049 void deallocate(void*);
00050 
00051 class NonTrackingAllocator
00052 {
00053 public:
00054     PX_FORCE_INLINE NonTrackingAllocator(const char* = 0)
00055     {
00056     }
00057     PX_FORCE_INLINE void* allocate(size_t size, const char* file, int line)
00058     {
00059         return !size ? 0 : GetNvClothAllocator()->allocate(size, "NonTrackedAlloc", file, line);
00060     }
00061     PX_FORCE_INLINE void deallocate(void* ptr)
00062     {
00063         if (ptr)
00064             GetNvClothAllocator()->deallocate(ptr);
00065     }
00066 };
00067 
00068 /* templated typedefs for convenience */
00069 
00070 template <typename T>
00071 struct Vector
00072 {
00073     typedef physx::shdfnd::Array<T, NonTrackingAllocator> Type;
00074 };
00075 
00076 template <typename T, size_t alignment>
00077 struct AlignedVector
00078 {
00079     typedef physx::shdfnd::Array<T, physx::shdfnd::AlignedAllocator<alignment, NonTrackingAllocator> > Type;
00080 };
00081 
00082 template <class Key, class Value, class HashFn = physx::shdfnd::Hash<Key> >
00083 struct HashMap
00084 {
00085     typedef physx::shdfnd::HashMap<Key, Value, HashFn, NonTrackingAllocator> Type;
00086 };
00087 
00088 struct NvClothOverload{};
00089 #define NV_CLOTH_NEW(T) new (__FILE__, __LINE__, nv::cloth::NvClothOverload()) T
00090 #define NV_CLOTH_ALLOC(n, name) GetNvClothAllocator()->allocate(n, name, __FILE__, __LINE__)
00091 #define NV_CLOTH_FREE(x) GetNvClothAllocator()->deallocate(x)
00092 #define NV_CLOTH_DELETE(x) delete x
00093 
00094 } // namespace cloth
00095 } // namespace nv
00096 
00097 //new/delete operators need to be declared in global scope
00098 template <typename T>
00099 PX_INLINE void* operator new(size_t size, const char* fileName,
00100                              typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00101 {
00102     PX_UNUSED(overload);
00103     return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00104 }
00105 
00106 template <typename T>
00107 PX_INLINE void* operator new [](size_t size, const char* fileName,
00108                                 typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00109 {
00110     PX_UNUSED(overload);
00111     return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00112 }
00113 
00114 // If construction after placement new throws, this placement delete is being called.
00115 template <typename T>
00116 PX_INLINE void operator delete(void* ptr, const char* fileName,
00117                                typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00118 {
00119     PX_UNUSED(fileName);
00120     PX_UNUSED(line);
00121     PX_UNUSED(overload);
00122 
00123     return GetNvClothAllocator()->deallocate(ptr);
00124 }
00125 
00126 // If construction after placement new throws, this placement delete is being called.
00127 template <typename T>
00128 PX_INLINE void operator delete [](void* ptr, const char* fileName,
00129                                   typename physx::shdfnd::EnableIfPod<T, int>::Type line, nv::cloth::NvClothOverload overload)
00130 {
00131     PX_UNUSED(fileName);
00132     PX_UNUSED(line);
00133     PX_UNUSED(overload);
00134 
00135     return GetNvClothAllocator()->deallocate(ptr);
00136 }
00137 
00138 namespace nv
00139 {
00140 namespace cloth
00141 {
00142 
00143 class UserAllocated
00144 {
00145   public:
00146     PX_INLINE void* operator new(size_t size, const char* fileName, int line, NvClothOverload overload)
00147     {
00148         PX_UNUSED(overload);
00149         return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00150     }
00151     PX_INLINE void* operator new [](size_t size, const char* fileName, int line, NvClothOverload overload)
00152     {
00153         PX_UNUSED(overload);
00154         return GetNvClothAllocator()->allocate(size, "<TypeName Unknown>", fileName, line);
00155     }
00156 
00157     // placement delete
00158     PX_INLINE void operator delete(void* ptr, const char* fileName, int line, NvClothOverload overload)
00159     {
00160         PX_UNUSED(fileName);
00161         PX_UNUSED(line);
00162         PX_UNUSED(overload);
00163         GetNvClothAllocator()->deallocate(ptr);
00164     }
00165     PX_INLINE void operator delete [](void* ptr, const char* fileName, int line, NvClothOverload overload)
00166     {
00167         PX_UNUSED(fileName);
00168         PX_UNUSED(line);
00169         PX_UNUSED(overload);
00170         GetNvClothAllocator()->deallocate(ptr);
00171     } 
00172     PX_INLINE void operator delete(void* ptr)
00173     {
00174         return GetNvClothAllocator()->deallocate(ptr);
00175     }
00176     PX_INLINE void operator delete [](void* ptr)
00177     {
00178         return GetNvClothAllocator()->deallocate(ptr);
00179     }
00180 };
00181 
00182 } // namespace cloth
00183 } // namespace nv
Copyright © 2016-2017 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com