SpeedTree
    Show / Hide Table of Contents

    SpeedTree New and Delete

    Since overriding global new and delete 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.

    These 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 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 passed in pointers to NULL.

    Copyright © 2023 Unity Technologies
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX.