summaryrefslogtreecommitdiff
path: root/inc/cad/util.h
diff options
context:
space:
mode:
Diffstat (limited to 'inc/cad/util.h')
-rw-r--r--inc/cad/util.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/inc/cad/util.h b/inc/cad/util.h
new file mode 100644
index 0000000..440d29b
--- /dev/null
+++ b/inc/cad/util.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <assert.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+static void resize_buffer(void **buffer, size_t *capacity, size_t elems, size_t elemSize) {
+ assert(elems > 0);
+ uint64_t newpower = (sizeof(elems) * CHAR_BIT) - __builtin_clzl(elems-1);
+ elems = 1 << newpower;
+
+ if(elems != *capacity) {
+ *capacity = elems;
+ *buffer = realloc(*buffer, *capacity * elemSize);
+ }
+}
+