@@ -50,9 +50,9 @@ class Memory {
5050 // └─────────────────┴──┴────────────────┴──┴───────────...
5151 // Offset: ↑ SIZE_OFFSET ↑ ELEMENT_OFFSET ↑ DATA_OFFSET
5252
53- static constexpr size_t SIZE_OFFSET = 0 ;
54- static constexpr size_t ELEMENT_OFFSET = ((SIZE_OFFSET + sizeof ( uint64_t )) % alignof ( uint64_t ) == 0 ) ? (SIZE_OFFSET + sizeof ( uint64_t )) : ((SIZE_OFFSET + sizeof ( uint64_t )) + alignof ( uint64_t ) - ((SIZE_OFFSET + sizeof ( uint64_t )) % alignof ( uint64_t ))) ;
55- static constexpr size_t DATA_OFFSET = ((ELEMENT_OFFSET + sizeof ( uint64_t )) % alignof ( max_align_t ) == 0 ) ? (ELEMENT_OFFSET + sizeof ( uint64_t )) : ((ELEMENT_OFFSET + sizeof ( uint64_t )) + alignof ( max_align_t ) - ((ELEMENT_OFFSET + sizeof ( uint64_t )) % alignof ( max_align_t ))) ;
53+ static const size_t SIZE_OFFSET;
54+ static const size_t ELEMENT_OFFSET;
55+ static const size_t DATA_OFFSET;
5656
5757 static void *alloc_static (size_t p_bytes, bool p_pad_align = false );
5858 static void *realloc_static (void *p_memory, size_t p_bytes, bool p_pad_align = false );
@@ -85,8 +85,19 @@ class Memory {
8585 static uint64_t get_mem_available ();
8686 static uint64_t get_mem_usage ();
8787 static uint64_t get_mem_max_usage ();
88+
89+ static constexpr size_t get_aligned_address (size_t p_address, size_t p_alignment);
8890};
8991
92+ constexpr size_t Memory::get_aligned_address (size_t p_address, size_t p_alignment) {
93+ const size_t n_bytes_unaligned = p_address % p_alignment;
94+ return (n_bytes_unaligned == 0 ) ? p_address : (p_address + p_alignment - n_bytes_unaligned);
95+ }
96+
97+ inline constexpr size_t Memory::SIZE_OFFSET = 0 ;
98+ inline constexpr size_t Memory::ELEMENT_OFFSET = get_aligned_address(SIZE_OFFSET + sizeof (uint64_t ), alignof (uint64_t ));
99+ inline constexpr size_t Memory::DATA_OFFSET = get_aligned_address(ELEMENT_OFFSET + sizeof (uint64_t ), alignof (max_align_t ));
100+
90101class DefaultAllocator {
91102public:
92103 _FORCE_INLINE_ static void *alloc (size_t p_memory) { return Memory::alloc_static (p_memory, false ); }
0 commit comments