VAE - Virtual Audio Engine 1
Small Data Driven Audio Engine
tklb::memory::tracer Namespace Reference

Classes

struct  MagicBlock
 Struct inserted at the end of every allocation. More...
 

Functions

static void * allocateTrace (size_t size, const char *file, int line) noexcept
 
static void * reallocateTrace (void *ptr, size_t size, const char *file, int line) noexcept
 
static void * clearallocateTrace (size_t num, size_t size, const char *file, int line) noexcept
 
static void deallocateTrace (void *ptr, const char *file, int line) noexcept
 
static void deallocateAlignedTrace (void *ptr, const char *file, int line) noexcept
 
static void * allocateAlignedTrace (const char *file, int line, size_t size, size_t align=DEFAULT_ALIGN) noexcept
 
template<class T , typename ... Args>
static T * createTrace (const char *file, int line, Args &&... args)
 
template<class T >
static void disposeTrace (T *ptr, const char *file, int line)
 
static void checkHeap ()
 Checks the MagicBlocks for all allocations. More...
 
static void init ()
 
static void stop ()
 

Variables

constexpr char TKLB_MAGIC_STRING [] = "tklbend"
 
constexpr char TKLB_MAGIC_BACKUP_STRING [] = "tklback"
 
HeapBuffer< MagicBlock * > MagicBlocks
 
bool EXCLUDE_TRACE = false
 

Function Documentation

◆ allocateAlignedTrace()

static void * tklb::memory::tracer::allocateAlignedTrace ( const char *  file,
int  line,
size_t  size,
size_t  align = DEFAULT_ALIGN 
)
inlinestaticnoexcept

Definition at line 174 of file TMemoryTracing.hpp.

174 {
175 if (EXCLUDE_TRACE) {
176 return allocateAligned(size, align);
177 }
178 void* mem = allocateAligned(size + sizeof(MagicBlock), align);
179 MagicBlock::construct(mem, size, file, line);
180 return mem;
181 };
Here is the call graph for this function:

◆ allocateTrace()

static void * tklb::memory::tracer::allocateTrace ( size_t  size,
const char *  file,
int  line 
)
inlinestaticnoexcept

Definition at line 124 of file TMemoryTracing.hpp.

124 {
125 if (EXCLUDE_TRACE) {
126 return allocate(size);
127 }
128 void* mem = allocate(size + sizeof(MagicBlock));
129 MagicBlock::construct(mem, size, file, line);
130 return mem;
131 };
Here is the call graph for this function:

◆ checkHeap()

static void tklb::memory::tracer::checkHeap ( )
static

Checks the MagicBlocks for all allocations.

Definition at line 209 of file TMemoryTracing.hpp.

209 {
210 if (MagicBlocks.data() == nullptr) { return; }
211 size_t total = 0;
212 for (size_t i = 0; i < MagicBlocks.size(); i++) {
213 MagicBlock* block = MagicBlocks[i];
214 MagicBlock::check(block);
215 total += block->size;
216 }
217 size_t blocks = MagicBlocks.allocated();
218 size_t left = Allocated;
219 left -= blocks;
220 TKLB_ASSERT(total == left)
221 }
#define TKLB_ASSERT(condition)
Wrap assertions.
Definition: TAssert.h:18
HeapBuffer< MagicBlock * > MagicBlocks
constexpr Vector3 left
Used in 7.1 and Headphones.
Definition: vae.hpp:317
Here is the call graph for this function:

◆ clearallocateTrace()

static void * tklb::memory::tracer::clearallocateTrace ( size_t  num,
size_t  size,
const char *  file,
int  line 
)
inlinestaticnoexcept

Definition at line 143 of file TMemoryTracing.hpp.

143 {
144 if (EXCLUDE_TRACE) {
145 return clearallocate(num, size);
146 }
147 // how much space clearallocate will allocate
148 size_t total = num * size;
149 // the amount of elements needed
150 size_t numNeeded = ((total + sizeof(MagicBlock)) / size) + 1;
151 void* mem = clearallocate(numNeeded, size);
152 MagicBlock::construct(mem, total, file, line);
153 return mem;
154 };
Here is the call graph for this function:

◆ createTrace()

template<class T , typename ... Args>
static T * tklb::memory::tracer::createTrace ( const char *  file,
int  line,
Args &&...  args 
)
inlinestatic

Definition at line 184 of file TMemoryTracing.hpp.

184 {
185 if (EXCLUDE_TRACE) {
186 void* mem = allocate(sizeof(T));
187 return new (mem) T(std::forward<Args>(args)...);
188 }
189 void* mem = allocate(sizeof(T) + sizeof(MagicBlock));
190 if (mem == nullptr) { return nullptr; }
191 MagicBlock::construct(mem, sizeof(T), file, line);
192 T* obj = new (mem) T(std::forward<Args>(args)...);
193 return obj;
194 }
Here is the call graph for this function:

◆ deallocateAlignedTrace()

static void tklb::memory::tracer::deallocateAlignedTrace ( void *  ptr,
const char *  file,
int  line 
)
inlinestaticnoexcept

Definition at line 165 of file TMemoryTracing.hpp.

165 {
166 if (EXCLUDE_TRACE) {
167 return deallocateAligned(ptr);
168 }
169 if (ptr == nullptr) { return; }
170 MagicBlock::destroy(ptr);
171 deallocateAligned(ptr);
172 };
Here is the call graph for this function:

◆ deallocateTrace()

static void tklb::memory::tracer::deallocateTrace ( void *  ptr,
const char *  file,
int  line 
)
inlinestaticnoexcept

Definition at line 156 of file TMemoryTracing.hpp.

156 {
157 if (EXCLUDE_TRACE) {
158 return deallocate(ptr);
159 }
160 if (ptr == nullptr) { return; }
161 MagicBlock::destroy(ptr);
162 deallocate(ptr);
163 };
Here is the call graph for this function:

◆ disposeTrace()

template<class T >
static void tklb::memory::tracer::disposeTrace ( T *  ptr,
const char *  file,
int  line 
)
inlinestatic

Definition at line 197 of file TMemoryTracing.hpp.

197 {
198 if (ptr == nullptr) { return; }
199 if (!EXCLUDE_TRACE) {
200 MagicBlock::destroy(ptr);
201 }
202 ptr->~T();
203 deallocate(ptr);
204 }
Here is the call graph for this function:

◆ init()

static void tklb::memory::tracer::init ( )
static

Definition at line 223 of file TMemoryTracing.hpp.

223 {
224 EXCLUDE_TRACE = true;
225 MagicBlocks.reserve(1024 * 1024);
226 EXCLUDE_TRACE = false;
227 }

◆ reallocateTrace()

static void * tklb::memory::tracer::reallocateTrace ( void *  ptr,
size_t  size,
const char *  file,
int  line 
)
inlinestaticnoexcept

Definition at line 133 of file TMemoryTracing.hpp.

133 {
134 if (EXCLUDE_TRACE) {
135 return reallocate(ptr, size);
136 }
137 MagicBlock::destroy(ptr);
138 void* mem = reallocate(ptr, size + sizeof(MagicBlock));
139 MagicBlock::construct(mem, size, file, line);
140 return mem;
141 };
Here is the call graph for this function:

◆ stop()

static void tklb::memory::tracer::stop ( )
static

Definition at line 229 of file TMemoryTracing.hpp.

229 {
230 EXCLUDE_TRACE = true;
231 MagicBlocks.resize(0);
232 }

Variable Documentation

◆ EXCLUDE_TRACE

bool tklb::memory::tracer::EXCLUDE_TRACE = false
inline

Definition at line 42 of file TMemoryTracing.hpp.

◆ MagicBlocks

HeapBuffer<MagicBlock*> tklb::memory::tracer::MagicBlocks
inline

Definition at line 41 of file TMemoryTracing.hpp.

◆ TKLB_MAGIC_BACKUP_STRING

constexpr char tklb::memory::tracer::TKLB_MAGIC_BACKUP_STRING[] = "tklback"
constexpr

Definition at line 37 of file TMemoryTracing.hpp.

◆ TKLB_MAGIC_STRING

constexpr char tklb::memory::tracer::TKLB_MAGIC_STRING[] = "tklbend"
constexpr

Definition at line 36 of file TMemoryTracing.hpp.