summaryrefslogtreecommitdiffstats
path: root/core/os/memory.cpp
diff options
context:
space:
mode:
authorbruvzg <7645683+bruvzg@users.noreply.github.com>2024-02-01 10:15:08 +0200
committerbruvzg <7645683+bruvzg@users.noreply.github.com>2024-02-05 17:30:02 +0200
commit7bcb41914907e17bfd5af934a031f783bb76b969 (patch)
treef8bf96183c9444a269804c02fee55a43be76d575 /core/os/memory.cpp
parent63d6bda8e95ac992da74e84b2f3be62f3d85190b (diff)
downloadredot-engine-7bcb41914907e17bfd5af934a031f783bb76b969.tar.gz
[Core] Improve `CowData` and `Memory` metadata alignment.
Diffstat (limited to 'core/os/memory.cpp')
-rw-r--r--core/os/memory.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/core/os/memory.cpp b/core/os/memory.cpp
index 5f6216a5f1..32c316e58e 100644
--- a/core/os/memory.cpp
+++ b/core/os/memory.cpp
@@ -72,23 +72,23 @@ void *Memory::alloc_static(size_t p_bytes, bool p_pad_align) {
bool prepad = p_pad_align;
#endif
- void *mem = malloc(p_bytes + (prepad ? PAD_ALIGN : 0));
+ void *mem = malloc(p_bytes + (prepad ? DATA_OFFSET : 0));
ERR_FAIL_NULL_V(mem, nullptr);
alloc_count.increment();
if (prepad) {
- uint64_t *s = (uint64_t *)mem;
- *s = p_bytes;
-
uint8_t *s8 = (uint8_t *)mem;
+ uint64_t *s = (uint64_t *)(s8 + SIZE_OFFSET);
+ *s = p_bytes;
+
#ifdef DEBUG_ENABLED
uint64_t new_mem_usage = mem_usage.add(p_bytes);
max_usage.exchange_if_greater(new_mem_usage);
#endif
- return s8 + PAD_ALIGN;
+ return s8 + DATA_OFFSET;
} else {
return mem;
}
@@ -108,8 +108,8 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
#endif
if (prepad) {
- mem -= PAD_ALIGN;
- uint64_t *s = (uint64_t *)mem;
+ mem -= DATA_OFFSET;
+ uint64_t *s = (uint64_t *)(mem + SIZE_OFFSET);
#ifdef DEBUG_ENABLED
if (p_bytes > *s) {
@@ -126,14 +126,14 @@ void *Memory::realloc_static(void *p_memory, size_t p_bytes, bool p_pad_align) {
} else {
*s = p_bytes;
- mem = (uint8_t *)realloc(mem, p_bytes + PAD_ALIGN);
+ mem = (uint8_t *)realloc(mem, p_bytes + DATA_OFFSET);
ERR_FAIL_NULL_V(mem, nullptr);
- s = (uint64_t *)mem;
+ s = (uint64_t *)(mem + SIZE_OFFSET);
*s = p_bytes;
- return mem + PAD_ALIGN;
+ return mem + DATA_OFFSET;
}
} else {
mem = (uint8_t *)realloc(mem, p_bytes);
@@ -158,10 +158,10 @@ void Memory::free_static(void *p_ptr, bool p_pad_align) {
alloc_count.decrement();
if (prepad) {
- mem -= PAD_ALIGN;
+ mem -= DATA_OFFSET;
#ifdef DEBUG_ENABLED
- uint64_t *s = (uint64_t *)mem;
+ uint64_t *s = (uint64_t *)(mem + SIZE_OFFSET);
mem_usage.sub(*s);
#endif