summaryrefslogtreecommitdiffstats
path: root/core/os/memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/os/memory.h')
-rw-r--r--core/os/memory.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/os/memory.h b/core/os/memory.h
index d03e08d785..033e417cb5 100644
--- a/core/os/memory.h
+++ b/core/os/memory.h
@@ -62,6 +62,30 @@ public:
static void *realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align = false);
static void free_static(void *p_ptr, bool p_pad_align = false);
+ // ↓ return value of alloc_aligned_static
+ // ┌─────────────────┬─────────┬─────────┬──────────────────┐
+ // │ padding (up to │ uint32_t│ void* │ padding (up to │
+ // │ p_alignment - 1)│ offset │ p_bytes │ p_alignment - 1) │
+ // └─────────────────┴─────────┴─────────┴──────────────────┘
+ //
+ // alloc_aligned_static will allocate p_bytes + p_alignment - 1 + sizeof(uint32_t) and
+ // then offset the pointer until alignment is satisfied.
+ //
+ // This offset is stored before the start of the returned ptr so we can retrieve the original/real
+ // start of the ptr in order to free it.
+ //
+ // The rest is wasted as padding in the beginning and end of the ptr. The sum of padding at
+ // both start and end of the block must add exactly to p_alignment - 1.
+ //
+ // p_alignment MUST be a power of 2.
+ static void *alloc_aligned_static(size_t p_bytes, size_t p_alignment);
+ static void *realloc_aligned_static(void *p_memory, size_t p_bytes, size_t p_prev_bytes, size_t p_alignment);
+ // Pass the ptr returned by alloc_aligned_static to free it.
+ // e.g.
+ // void *data = realloc_aligned_static( bytes, 16 );
+ // free_aligned_static( data );
+ static void free_aligned_static(void *p_memory);
+
static uint64_t get_mem_available();
static uint64_t get_mem_usage();
static uint64_t get_mem_max_usage();