From: APTX Date: Sat, 9 Apr 2011 12:38:31 +0000 (+0200) Subject: Add ol_aligned_malloc. X-Git-Url: https://gitweb.aptx.org/?a=commitdiff_plain;h=954533f958be772830e15e0fff66fbb3a4c5335b;p=openlase.git Add ol_aligned_malloc. --- diff --git a/libol/ol_malloc.c b/libol/ol_malloc.c new file mode 100644 index 0000000..76f747a --- /dev/null +++ b/libol/ol_malloc.c @@ -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 index 0000000..d01e7f5 --- /dev/null +++ b/libol/ol_malloc.h @@ -0,0 +1,10 @@ +#ifndef OL_MALLOC_H +#define OL_MALLOC_H + +#include + +void *ol_aligned_malloc(size_t size, size_t alignment); +void ol_aligned_free(void *mem); + + +#endif \ No newline at end of file diff --git a/libol/trace.c b/libol/trace.c index 176e5e8..89d6de5 100644 --- a/libol/trace.c +++ b/libol/trace.c @@ -40,7 +40,7 @@ object start/end points near the edges of the screen (less visible). #include #include #include -#include +#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)