Memory allocation {#memory} =============== When allocating memory in Banshee it is prefered (but not required) to use Banshee's allocator functions instead of the standard *new* / *delete* operators or *malloc* / *free*. Use @ref bs::bs_new "bs_new" instead of *new* and @ref bs::bs_delete "bs_delete" instead of *delete*. Use @ref bs::bs_newN "bs_newN" instead of *new[]* and @ref bs::bs_deleteN "bs_deleteN" instead of *delete[]*. Use @ref bs::bs_alloc "bs_alloc" instead of *malloc* and @ref bs::bs_free "bs_free" instead of *free*. This ensures the Banshee can keep track of all allocated memory, which ensures better debugging and profiling tools and ensures the internal memory allocation method can be changed in the future. ~~~~~~~~~~~~~{.cpp} // Helper structure struct MyStruct { MyStruct() {} MyStruct(int a, bool b) :a(a), b(b) { } int a; bool b; }; // Allocating memory the normal way MyStruct* ptr = new MyStruct(123, false); MyStruct** ptrArray = new MyStruct[5]; void* rawMem = malloc(12); delete ptr; delete[] ptrArray; free(rawMem); // Allocating memory the Banshee way MyStruct* bsPtr = bs_new(123, false); MyStruct** bsPtrArray = bs_newN(5); void* bsRawMem = bs_alloc(12); bs_delete(bsPtr); bs_deleteN(bsPtrArray, 5); bs_free(bsRawMem); ~~~~~~~~~~~~~