Configuration - WzrdIsTaken/Nabi-Allocator GitHub Wiki
Settings
Much of NabiAllocator's functionality can be toggled on and off via the defines in Config.h
. In the single header, these defines are at the very top of the file.
You should consider toggling NA_DEBUG
, NA_TRACK_ALLOCATIONS
, NA_MEMORY_TAGGING
and all of the testing defines (NA_[TESTS/BENCHMARKS/WORKFLOWS]
) off in release builds.
NA_OVERRIDE_NEW_DELETE
Routes new
and delete
calls through NabiAllocator's MemoryCommand
.
NA_DEBUG
Enables asserts and logging. If you want to override NabiAllocator's assert and logging macros, see the Debug section below.
NA_NON_STANDARD_CPP
Use non standard C++ syntax such as __forceinline.
NA_DEFINE_SHORT_NAMESPACE
Defines the namespace alias na
so you don't have to write out nabi_allocator
every time.
NA_THREAD_LOCAL_HEAPS
With this define on, each thread will have its own stack of heap zones and memory tags. Note if one thread allocates some memory, and another frees it - this will still work fine.
NA_MALLOC_IF_OUT_OF_MEMORY
If a HeapZone
is out of memory, rather than asserting and failing to allocate just try and malloc the memory. Note: This will only happen if the MemoryCommand
requests the allocation.
NA_SAFE_ALLOC_FREE_EARLY_OUT
The MemoryCommand
will perform an additional check to see if an allocation or free is going to fail (eg: freeing nullptr) and early out if necessary. Note: an assert will still fire.
NA_THREAD_SAFE_HEAP_ZONE
Adds a mutex/lock in HeapZone::Allocate
and HeapZone::Free
.
NA_TRACK_ALLOCATIONS
Memory allocators will track the count and total size of active and all time allocated objects. You can get this information with AllocatorBase::GetStats
. This information is also used internally to trigger asserts, for example when an allocator is destroyed but all the objects it allocated haven't been freed.
NA_MEMORY_TAGGING
Adds metadata to all blocks. Note: this increases the size of each block by sizeof(nabi_allocator::memoryTag)
(defined in MemoryConstants.h
).
NA_TESTS
Run the unit tests. Note: tests are implemented with GoogleTest.
NA_BENCHMARKS
Run the benchmarks. Note: benchmarks are implemented with GoogleTest.
NA_WORKFLOWS
Run the workflow tests. Note: tests are implemented with GoogleTest.
NA_BENCHMARK_RUN_COUNT
If NA_BENCHMARKS
is defined, how many times to run each benchmark.
Debug
To change the NabiAllocator's asserts and logging, you can provide your own implementation for the NA_ASSERT_DEFINTION
and NA_LOG_DEFINTION
macros (defined at the top of the single header file). If you just want to toggle them off, comment out NA_DEBUG
(described above).
If you override NA_ASSERT_DEFINTION
you will notice there is no condition parameter. This is because internally the condition check happens before NA_ASSERT_DEFINTION
is called. Therefore, make sure your assert will always fire. Eg: assert(false)
.
The message
parameter for both these macros is a std::string
.