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

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

#include <TMemoryTracing.hpp>

Collaboration diagram for tklb::memory::tracer::MagicBlock:

Public Member Functions

 MagicBlock (const char *f, int l, void *p, size_t s)
 

Static Public Member Functions

static void construct (void *ptr, size_t s, const char *f, int l)
 Placement new at the end of the allocation. More...
 
static bool compare (const char *a, const char *b, size_t s)
 
static void check (MagicBlock *block)
 checks if the allocation is still intact More...
 
static MagicBlockfind (void *start)
 Find the MagicBlock for a given allocation. More...
 
static void destroy (void *start)
 

Public Attributes

char magic [sizeof(TKLB_MAGIC_STRING)]
 
char padding [1000]
 
char magicBackup [sizeof(TKLB_MAGIC_BACKUP_STRING)]
 
const char * file
 
int line
 
void * ptr
 
size_t size
 

Detailed Description

Struct inserted at the end of every allocation.

Definition at line 47 of file TMemoryTracing.hpp.

Constructor & Destructor Documentation

◆ MagicBlock()

tklb::memory::tracer::MagicBlock::MagicBlock ( const char *  f,
int  l,
void *  p,
size_t  s 
)
inline

Definition at line 55 of file TMemoryTracing.hpp.

55 {
56 file = f;
57 line = l;
58 ptr = p;
59 size = s;
60 memory::set(magic, 0, sizeof(magic));
63 }
constexpr char TKLB_MAGIC_BACKUP_STRING[]
constexpr char TKLB_MAGIC_STRING[]
static void set(void *dst, const unsigned char val, size_t size)
memset wrapper
Definition: TMemoryUtil.hpp:40
static void copy(void *dst, const void *src, const size_t size)
memcpy wrapper
Definition: TMemoryUtil.hpp:14
char magicBackup[sizeof(TKLB_MAGIC_BACKUP_STRING)]
char magic[sizeof(TKLB_MAGIC_STRING)]
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ check()

static void tklb::memory::tracer::MagicBlock::check ( MagicBlock block)
inlinestatic

checks if the allocation is still intact

Definition at line 90 of file TMemoryTracing.hpp.

90 {
91 if (!compare(block->magic, TKLB_MAGIC_STRING, sizeof(TKLB_MAGIC_STRING))) {
92 if (!compare(block->magicBackup, TKLB_MAGIC_BACKUP_STRING, sizeof(TKLB_MAGIC_BACKUP_STRING))) {
93 // Magic backup string is wrong, this shouldn't happen and somethings wrong
94 TKLB_ASSERT(false)
95 }
96 TKLB_ASSERT(false) // Magic string is wrong so it was overrun
97 }
98 }
#define TKLB_ASSERT(condition)
Wrap assertions.
Definition: TAssert.h:18
static bool compare(const char *a, const char *b, size_t s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ compare()

static bool tklb::memory::tracer::MagicBlock::compare ( const char *  a,
const char *  b,
size_t  s 
)
inlinestatic

Definition at line 78 of file TMemoryTracing.hpp.

78 {
79 for (size_t i = 0; i < s; i++) {
80 if (a[i] != b[i]) {
81 return false;
82 }
83 }
84 return true;
85 }
Here is the caller graph for this function:

◆ construct()

static void tklb::memory::tracer::MagicBlock::construct ( void *  ptr,
size_t  s,
const char *  f,
int  l 
)
inlinestatic

Placement new at the end of the allocation.

Definition at line 68 of file TMemoryTracing.hpp.

68 {
69 if (ptr == nullptr) { return; }
70 MagicBlock* loc = reinterpret_cast<MagicBlock*>(static_cast<char*>(ptr) + s);
71 MagicBlock* block = new (loc) MagicBlock(f, l, ptr, s);
72 EXCLUDE_TRACE = true;
73 TKLB_ASSERT(block != nullptr)
74 MagicBlocks.push(block);
75 EXCLUDE_TRACE = false;
76 }
HeapBuffer< MagicBlock * > MagicBlocks
MagicBlock(const char *f, int l, void *p, size_t s)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ destroy()

static void tklb::memory::tracer::MagicBlock::destroy ( void *  start)
inlinestatic

Definition at line 114 of file TMemoryTracing.hpp.

114 {
115 if (start == nullptr) { return; }
116 if (MagicBlocks.data() == nullptr) { return; }
117 MagicBlock* block = find(start);
118 TKLB_ASSERT(block != nullptr)
119 check(block);
120 MagicBlocks.remove(block);
121 }
static MagicBlock * find(void *start)
Find the MagicBlock for a given allocation.
static void check(MagicBlock *block)
checks if the allocation is still intact
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find()

static MagicBlock * tklb::memory::tracer::MagicBlock::find ( void *  start)
inlinestatic

Find the MagicBlock for a given allocation.

Definition at line 103 of file TMemoryTracing.hpp.

103 {
104 if (MagicBlocks.data() == nullptr) { return nullptr; }
105 for (size_t i = 0; i < MagicBlocks.size(); i++) {
106 MagicBlock* block = MagicBlocks[i];
107 if (block->ptr == start) {
108 return block;
109 }
110 }
111 return nullptr;
112 }
Here is the caller graph for this function:

Member Data Documentation

◆ file

const char* tklb::memory::tracer::MagicBlock::file

Definition at line 51 of file TMemoryTracing.hpp.

◆ line

int tklb::memory::tracer::MagicBlock::line

Definition at line 52 of file TMemoryTracing.hpp.

◆ magic

char tklb::memory::tracer::MagicBlock::magic[sizeof(TKLB_MAGIC_STRING)]

Definition at line 48 of file TMemoryTracing.hpp.

◆ magicBackup

char tklb::memory::tracer::MagicBlock::magicBackup[sizeof(TKLB_MAGIC_BACKUP_STRING)]

Definition at line 50 of file TMemoryTracing.hpp.

◆ padding

char tklb::memory::tracer::MagicBlock::padding[1000]

Definition at line 49 of file TMemoryTracing.hpp.

◆ ptr

void* tklb::memory::tracer::MagicBlock::ptr

Definition at line 53 of file TMemoryTracing.hpp.

◆ size

size_t tklb::memory::tracer::MagicBlock::size

Definition at line 54 of file TMemoryTracing.hpp.


The documentation for this struct was generated from the following file: