aboutsummaryrefslogtreecommitdiff
path: root/src/common.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-07 14:25:48 +0100
committergingerBill <bill@gingerbill.org>2021-08-07 14:25:48 +0100
commit571170fd30b116c2b6cf40835c2f4779631741cf (patch)
tree7f27abcd08278677e09242f692791e1e2891e6d7 /src/common.cpp
parent911c428dacdeda1667147861a0b055068b543b72 (diff)
Improve and simplify the memory layout of `MPMCQueue`
Diffstat (limited to 'src/common.cpp')
-rw-r--r--src/common.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 4aea379c3..5e5ec3490 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -228,6 +228,28 @@ GB_ALLOCATOR_PROC(heap_allocator_proc) {
return ptr;
}
+
+template <typename T>
+void resize_array_raw(T **array, gbAllocator const &a, isize old_count, isize new_count) {
+ GB_ASSERT(new_count >= 0);
+ if (new_count == 0) {
+ gb_free(a, *array);
+ *array = nullptr;
+ return;
+ }
+ if (new_count < old_count) {
+ return;
+ }
+ isize old_size = old_count * gb_size_of(T);
+ isize new_size = new_count * gb_size_of(T);
+ isize alignment = gb_align_of(T);
+ auto new_data = cast(T *)gb_resize_align(a, *array, old_size, new_size, alignment);
+ GB_ASSERT(new_data != nullptr);
+ *array = new_data;
+}
+
+
+
#include "unicode.cpp"
#include "array.cpp"
#include "string.cpp"