Go to the source code of this file.
|
#define | ALLOC nullalloc |
| An allocator that prints to stdout when it allocates or frees memory.
|
◆ ALLOC
An allocator that prints to stdout when it allocates or frees memory.
- Takes a specific instance, so we can define different printers for
Definition at line 17 of file template.h.
◆ calloc()
void * calloc |
( |
SELF * | self, |
|
|
size_t | count, |
|
|
size_t | size ) |
|
static |
Definition at line 40 of file template.h.
40 {
43 if (ptr) {
44 printf(
"%s allocated %zu bytes at %p\n", self->
name, count *
size, ptr);
45 } else {
46 printf(
"%s failed to allocate %zu bytes\n", self->
name, count *
size);
47 }
48 return ptr;
49}
#define ALLOC
An allocator that prints to stdout when it allocates or frees memory.
static void * calloc(SELF *self, size_t count, size_t size)
#define DEBUG_ASSERT(expr)
static INDEX_TYPE size(SELF const *self)
◆ free()
void free |
( |
SELF * | self, |
|
|
void * | ptr ) |
|
static |
◆ malloc()
void * malloc |
( |
SELF * | self, |
|
|
size_t | size ) |
|
static |
- Examples
- structures/arena.c.
Definition at line 29 of file template.h.
29 {
32 if (ptr) {
33 printf(
"%s allocated %zu bytes at %p\n", self->
name,
size, ptr);
34 } else {
35 printf(
"%s failed to allocate %zu bytes\n", self->
name,
size);
36 }
37 return ptr;
38}
static void * malloc(SELF *self, size_t size)
◆ new()
SELF new |
( |
char const * | name, |
|
|
ALLOC * | alloc ) |
|
static |
◆ realloc()
void * realloc |
( |
SELF * | self, |
|
|
void * | ptr, |
|
|
size_t | size ) |
|
static |
Definition at line 51 of file template.h.
51 {
54 if (new_ptr) {
55 printf(
"%s reallocated memory at %p to %zu bytes\n", self->
name, new_ptr,
size);
56 } else {
57 printf(
"%s failed to reallocate memory at %p to %zu bytes\n", self->
name, ptr,
size);
58 }
59 return new_ptr;
60}
static void * realloc(SELF *self, void *ptr, size_t size)