3030
3131#include " memory.h"
3232
33+ #include " core/profiling/profiling.h"
3334#include " core/templates/safe_refcount.h"
3435
3536#include < cstdlib>
@@ -68,6 +69,7 @@ void *Memory::alloc_aligned_static(size_t p_bytes, size_t p_alignment) {
6869 if ((p1 = (void *)malloc (p_bytes + p_alignment - 1 + sizeof (uint32_t ))) == nullptr ) {
6970 return nullptr ;
7071 }
72+ GodotProfileAlloc (p1, p_bytes + p_alignment - 1 + sizeof (uint32_t ));
7173
7274 p2 = (void *)(((uintptr_t )p1 + sizeof (uint32_t ) + p_alignment - 1 ) & ~((p_alignment)-1 ));
7375 *((uint32_t *)p2 - 1 ) = (uint32_t )((uintptr_t )p2 - (uintptr_t )p1);
@@ -90,6 +92,7 @@ void *Memory::realloc_aligned_static(void *p_memory, size_t p_bytes, size_t p_pr
9092void Memory::free_aligned_static (void *p_memory) {
9193 uint32_t offset = *((uint32_t *)p_memory - 1 );
9294 void *p = (void *)((uint8_t *)p_memory - offset);
95+ GodotProfileFree (p);
9396 free (p);
9497}
9598
@@ -107,6 +110,7 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
107110 } else {
108111 mem = malloc (p_bytes + (prepad ? DATA_OFFSET : 0 ));
109112 }
113+ GodotProfileAlloc (mem, p_bytes + (prepad ? DATA_OFFSET : 0 ));
110114
111115 ERR_FAIL_NULL_V (mem, nullptr );
112116
@@ -156,13 +160,16 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
156160#endif
157161
158162 if (p_bytes == 0 ) {
163+ GodotProfileFree (mem);
159164 free (mem);
160165 return nullptr ;
161166 } else {
162167 *s = p_bytes;
163168
169+ GodotProfileFree (mem);
164170 mem = (uint8_t *)realloc (mem, p_bytes + DATA_OFFSET);
165171 ERR_FAIL_NULL_V (mem, nullptr );
172+ GodotProfileAlloc (mem, p_bytes + DATA_OFFSET);
166173
167174 s = (uint64_t *)(mem + SIZE_OFFSET);
168175
@@ -171,7 +178,9 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
171178 return mem + DATA_OFFSET;
172179 }
173180 } else {
181+ GodotProfileFree (mem);
174182 mem = (uint8_t *)realloc (mem, p_bytes);
183+ GodotProfileAlloc (mem, p_bytes);
175184
176185 ERR_FAIL_COND_V (mem == nullptr && p_bytes > 0 , nullptr );
177186
@@ -198,8 +207,10 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) {
198207 _current_mem_usage.sub (*s);
199208#endif
200209
210+ GodotProfileFree (mem);
201211 free (mem);
202212 } else {
213+ GodotProfileFree (mem);
203214 free (mem);
204215 }
205216}
0 commit comments