void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) { if (p_memory == NULL) { return alloc_static(p_bytes, p_pad_align); } uint8_t *mem = (uint8_t *)p_memory; #ifdef DEBUG_ENABLED bool prepad = true; #else bool prepad = p_pad_align; #endif if (prepad) { mem -= PAD_ALIGN; uint64_t *s = (uint64_t *)mem; #ifdef DEBUG_ENABLED if (p_bytes > *s) { atomic_add(&mem_usage, p_bytes - *s); atomic_exchange_if_greater(&max_usage, mem_usage); } else { atomic_sub(&mem_usage, *s - p_bytes); } #endif if (p_bytes == 0) { free(mem); return NULL; } else { *s = p_bytes; mem = (uint8_t *)realloc(mem, p_bytes + PAD_ALIGN); ERR_FAIL_COND_V(!mem, NULL); s = (uint64_t *)mem; *s = p_bytes; return mem + PAD_ALIGN; } } else { mem = (uint8_t *)realloc(mem, p_bytes); ERR_FAIL_COND_V(mem == NULL && p_bytes > 0, NULL); return mem; } }
void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) { if (p_memory == NULL) { return alloc_static(p_bytes, p_pad_align); } uint8_t *mem = (uint8_t *)p_memory; #ifdef DEBUG_ENABLED bool prepad = true; #else bool prepad = p_pad_align; #endif if (prepad) { mem -= PAD_ALIGN; uint64_t *s = (uint64_t *)mem; #ifdef DEBUG_ENABLED mem_usage -= *s; mem_usage += p_bytes; #endif if (p_bytes == 0) { free(mem); return NULL; } else { *s = p_bytes; mem = (uint8_t *)realloc(mem, p_bytes + PAD_ALIGN); ERR_FAIL_COND_V(!mem, NULL); s = (uint64_t *)mem; *s = p_bytes; return mem + PAD_ALIGN; } } else { mem = (uint8_t *)realloc(mem, p_bytes); ERR_FAIL_COND_V(mem == NULL && p_bytes > 0, NULL); return mem; } }