aboutsummaryrefslogtreecommitdiff
path: root/teensy/teensy_mem.h
blob: 8639479bf839a29c688f0e8027c3f322dc0d29f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#ifndef TEENSY_MEM_H_
#define TEENSY_MEM_H_

#include <stdlib.h>

#define ty_new(T) (ty_alloc(sizeof(T)))

// NOTE: Overrides GLFW allocator
void ty_init_mem(void);
void ty_deinit_mem(void);
void ty_free_temp_allocs(void);
// Temp allocation. Freed at the end of every frame. Do NOT realloc.
void *ty_talloc(size_t size);

// These mem_* functions handle the case of a bad allocation. No need to check
// for NULL after allocating with these. In debug builds, they will also track
// allocations and report any memory still in use when the program exits.

void *ty_alloc(size_t size);
void *ty_realloc(void *ptr, size_t new_size);
void ty_free(void *ptr);

// Returns -1 in release builds.
int ty_alloc_count(void);
// Returns 0 in release builds.
size_t ty_alloc_size(void);

#endif // TEENSY_MEM_H_