]> Some of my projects - openlase.git/commitdiff
Add ol_aligned_malloc.
authorAPTX <marek321@gmail.com>
Sat, 9 Apr 2011 12:38:31 +0000 (14:38 +0200)
committerAPTX <marek321@gmail.com>
Sat, 9 Apr 2011 12:38:42 +0000 (14:38 +0200)
libol/ol_malloc.c [new file with mode: 0644]
libol/ol_malloc.h [new file with mode: 0644]
libol/trace.c

diff --git a/libol/ol_malloc.c b/libol/ol_malloc.c
new file mode 100644 (file)
index 0000000..76f747a
--- /dev/null
@@ -0,0 +1,23 @@
+#include "ol_malloc.h"
+
+#ifdef OL_MALLOC_WINDOWS
+void *ol_aligned_malloc(size_t size, size_t alignment)
+{
+       return _aligned_malloc(size, alignment);
+}
+
+void ol_aligned_free(void *mem)
+{
+       return _aligned_free(mem);
+}
+#else
+void *ol_aligned_malloc(size_t size, size_t alignment)
+{
+       return memalign(alignment, size);
+}
+
+void ol_aligned_free(void *mem)
+{
+       return free(mem);
+}
+#endif
\ No newline at end of file
diff --git a/libol/ol_malloc.h b/libol/ol_malloc.h
new file mode 100644 (file)
index 0000000..d01e7f5
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef OL_MALLOC_H
+#define OL_MALLOC_H
+
+#include <malloc.h>
+
+void *ol_aligned_malloc(size_t size, size_t alignment);
+void ol_aligned_free(void *mem);
+
+
+#endif
\ No newline at end of file
index 176e5e80c2bb89dc36a656421f6dcd4b1f1cb9ea..89d6de5b532ee0b08f43950125a591ce79aa7b6f 100644 (file)
@@ -40,7 +40,7 @@ object start/end points near the edges of the screen (less visible).
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <malloc.h>
+#include "ol_malloc.h"
 
 #include "trace.h"
 
@@ -100,21 +100,21 @@ static void alloc_bufs(OLTraceCtx *ctx)
                ctx->btbuf = NULL;
                ctx->sibuf = NULL;
        } else {
-           ctx->k = memalign(64, 16 * ctx->ksize);
+           ctx->k = ol_aligned_malloc(16 * ctx->ksize, 64);
                ctx->kpad = ctx->ksize / 2;
 
-               ctx->bibuf = memalign(64, ctx->aw * (ctx->ah + 2 * ctx->kpad));
-               ctx->btbuf = memalign(64, ctx->ah * (ctx->aw + 2 * ctx->kpad));
-               ctx->sibuf = memalign(64, ctx->aw * (ctx->ah + 2));
+               ctx->bibuf = ol_aligned_malloc(ctx->aw * (ctx->ah + 2 * ctx->kpad), 64);
+               ctx->btbuf = ol_aligned_malloc(ctx->ah * (ctx->aw + 2 * ctx->kpad), 64);
+               ctx->sibuf = ol_aligned_malloc(ctx->aw * (ctx->ah + 2), 64);
        }
 
        if (ctx->p.mode == OL_TRACE_CANNY) {
                if (!ctx->sibuf)
-                       ctx->sibuf = memalign(64, ctx->aw * (ctx->ah + 2));
-               ctx->stbuf = memalign(64, sizeof(*ctx->stbuf) * ctx->ah * (ctx->aw + 2));
-               ctx->sxbuf = memalign(64, sizeof(*ctx->sxbuf) * ctx->aw * ctx->ah);
-               ctx->sybuf = memalign(64, sizeof(*ctx->sybuf) * ctx->aw * ctx->ah);
-               ctx->smbuf = memalign(64, sizeof(*ctx->smbuf) * ctx->aw * ctx->ah);
+                       ctx->sibuf = ol_aligned_malloc(ctx->aw * (ctx->ah + 2), 64);
+               ctx->stbuf = ol_aligned_malloc(sizeof(*ctx->stbuf) * ctx->ah * (ctx->aw + 2), 64);
+               ctx->sxbuf = ol_aligned_malloc(sizeof(*ctx->sxbuf) * ctx->aw * ctx->ah, 64);
+               ctx->sybuf = ol_aligned_malloc(sizeof(*ctx->sybuf) * ctx->aw * ctx->ah, 64);
+               ctx->smbuf = ol_aligned_malloc(sizeof(*ctx->smbuf) * ctx->aw * ctx->ah, 64);
        } else {
                ctx->stbuf = NULL;
                ctx->sxbuf = NULL;
@@ -145,21 +145,21 @@ static void free_bufs(OLTraceCtx *ctx)
        if (ctx->pb)
                free(ctx->pb);
        if (ctx->k)
-               free(ctx->k);
+               ol_aligned_free(ctx->k);
        if (ctx->bibuf)
-               free(ctx->bibuf);
+               ol_aligned_free(ctx->bibuf);
        if (ctx->btbuf)
-               free(ctx->btbuf);
+               ol_aligned_free(ctx->btbuf);
        if (ctx->sibuf)
-               free(ctx->sibuf);
+               ol_aligned_free(ctx->sibuf);
        if (ctx->stbuf)
-               free(ctx->stbuf);
+               ol_aligned_free(ctx->stbuf);
        if (ctx->sxbuf)
-               free(ctx->sxbuf);
+               ol_aligned_free(ctx->sxbuf);
        if (ctx->sybuf)
-               free(ctx->sybuf);
+               ol_aligned_free(ctx->sybuf);
        if (ctx->smbuf)
-               free(ctx->smbuf);
+               ol_aligned_free(ctx->smbuf);
 }
 
 static void init_blur(OLTraceCtx *ctx)