Since overriding global new and delete is not a viable option for a library (these function 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 allocator interface.
These functions should only be used when:
Note that these functions are not expected to be widely used and are by no means a requirement for SpeedTree integration. There are four functions, duplicating the functionality of new, new[], delete, and delete[]. Prototypes and example usages for each follow:
// 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 parameters CMyObject* pObject = st_new(CMyObject, "description here"); // example usage if object constructor takes two parameters CMyObject* 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 usage CMyObject* 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 usage CMyObject* pObject = new ("description here") CMyObject; st_delete<CMyObject>(pObject); // operator delete[] equivalent (must be paired with st_new_array()) template <typename TYPE> inline void st_delete_array(TYPE*& pRawBlock, const char* pDescription); // example usage CMyObject* pObjects = st_new_array<CMyObject>(10, "description here"); st_delete_array<CMyObject>(pObjects);
Note: The delete functions will automatically set the pointers passed in to NULL. |
---|