summaryrefslogtreecommitdiff
path: root/zutil_p.h
diff options
context:
space:
mode:
authorHans Kristian Rosbach <hk-git@circlestorm.org>2020-09-12 19:54:38 +0200
committerHans Kristian Rosbach <hk-github@circlestorm.org>2020-09-14 12:04:30 +0200
commit696e387ef1b587376baf9326ad0bb89cd7948236 (patch)
tree1aa2e8a4f0afd2a10477c8358aeca6d4fff13616 /zutil_p.h
parenta245ef38b8854d8de333f3575158046cc115a6ac (diff)
Simplify zng_calloc and zng_cfree.
Make new static functions zng_alloc and zng_free available to other parts of the code. Always request aligned allocations, even if UNALIGNED_OK is set.
Diffstat (limited to 'zutil_p.h')
-rw-r--r--zutil_p.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/zutil_p.h b/zutil_p.h
new file mode 100644
index 0000000..b39fc28
--- /dev/null
+++ b/zutil_p.h
@@ -0,0 +1,34 @@
+/* zutil_p.h -- Private inline functions used internally in zlib-ng
+ *
+ */
+
+#ifndef ZUTIL_P_H
+#define ZUTIL_P_H
+
+#ifdef __APPLE__
+# include <stdlib.h>
+#else
+# include <malloc.h>
+#endif
+
+/* Function to allocate 16-byte aligned memory */
+static inline void *zng_alloc(size_t size) {
+#if defined(_WIN32)
+ return (void *)_aligned_malloc(size, 16);
+#elif defined(__APPLE__)
+ return (void *)malloc(size); /* MacOS always aligns to 16 bytes */
+#else
+ return (void *)memalign(16, size);
+#endif
+}
+
+/* Function that can free aligned memory */
+static inline void zng_free(void *ptr) {
+#if defined(_WIN32)
+ _aligned_free(ptr);
+#else
+ free(ptr);
+#endif
+}
+
+#endif