SpeedTree New and Delete
Learn about SpeedTree's custom memory allocator functions.
Read time 2 minutesLast updated 2 hours ago
Since overriding global and functions is not a viable option for a library (these functions are free to be overridden by the application if desired), a set of allocator functions were created for use by SpeedTree-associated code that would properly redirect the allocations through SpeedTree's heap allocation callback system.
newdeleteThese functions should only be used when:
-
The application is using the SpeedTree allocator interface.
-
The application developer has deemed it useful for the dynamic allocation to be tracked together with the rest of the SpeedTree memory, as may be done when writing custom wrapper code.
Note that these functions are not expected to be widely used and are not a requirement for SpeedTree integration. There are four functions, duplicating the functionality of , , , and . Prototypes and example usages for each follow:
newnew[]deletedelete[]// operator new equivalent (must be paired with st_delete())#define st_new(TYPE, pDescription) new (st_allocate<TYPE>(pDescription)) TYPE // example usage if object constructor takes no parametersCMyObject* pObject = st_new(CMyObject, "description here");// example usage if object constructor takes two parametersCMyObject* pObject = st_new(CMyObject, "description here")(constr_param1, constr_param2); // operator new[] equivalent (must be paired with st_delete_array())template <typename TYPE> inline TYPE* st_new_array(size_t sNumElements, const char* pDescription);// example usageCMyObject* pObjects = st_new_array<CMyObject>(10, "description here"); // operator delete equivalent (must be paired with placement new declared above)template <typename TYPE> inline void st_delete(TYPE*& pBlock, const char* pDescription); // example usageCMyObject* pObject = st_new(CMyObject, "description here");st_delete<CMyObject>(pObject, "description here");// operator delete[] equivalent (must be paired with st_new_array())template <typename TYPE> inline void st_delete_array(TYPE*& pRawBlock, const char* pDescription);// example usageCMyObject* pObjects = st_new_array<CMyObject>(10, "description here");st_delete_array<CMyObject>(pObjects, "description here");