@@ -64,6 +64,30 @@ class Memory {
64
64
static void *realloc_static (void *p_memory, size_t p_bytes, bool p_pad_align = false );
65
65
static void free_static (void *p_ptr, bool p_pad_align = false );
66
66
67
+ // ↓ return value of alloc_aligned_static
68
+ // ┌─────────────────┬─────────┬─────────┬──────────────────┐
69
+ // │ padding (up to │ uint32_t│ void* │ padding (up to │
70
+ // │ p_alignment - 1)│ offset │ p_bytes │ p_alignment - 1) │
71
+ // └─────────────────┴─────────┴─────────┴──────────────────┘
72
+ //
73
+ // alloc_aligned_static will allocate p_bytes + p_alignment - 1 + sizeof(uint32_t) and
74
+ // then offset the pointer until alignment is satisfied.
75
+ //
76
+ // This offset is stored before the start of the returned ptr so we can retrieve the original/real
77
+ // start of the ptr in order to free it.
78
+ //
79
+ // The rest is wasted as padding in the beginning and end of the ptr. The sum of padding at
80
+ // both start and end of the block must add exactly to p_alignment - 1.
81
+ //
82
+ // p_alignment MUST be a power of 2.
83
+ static void *alloc_aligned_static (size_t p_bytes, size_t p_alignment);
84
+ static void *realloc_aligned_static (void *p_memory, size_t p_bytes, size_t p_prev_bytes, size_t p_alignment);
85
+ // Pass the ptr returned by alloc_aligned_static to free it.
86
+ // e.g.
87
+ // void *data = realloc_aligned_static( bytes, 16 );
88
+ // free_aligned_static( data );
89
+ static void free_aligned_static (void *p_memory);
90
+
67
91
static uint64_t get_mem_available ();
68
92
static uint64_t get_mem_usage ();
69
93
static uint64_t get_mem_max_usage ();
0 commit comments