gegl r2196 - in trunk: . gegl



Author: ok
Date: Fri Apr 18 22:28:05 2008
New Revision: 2196
URL: http://svn.gnome.org/viewvc/gegl?rev=2196&view=rev

Log:
* gegl/gegl-utils.c: (gegl_malloc), (gegl_free): modified custom
aligned malloc to reserve allocation + align + sizeof(pointer) and
store the underlying malloc one pointer in front of the returned
buffer.


Modified:
   trunk/ChangeLog
   trunk/gegl/gegl-utils.c

Modified: trunk/gegl/gegl-utils.c
==============================================================================
--- trunk/gegl/gegl-utils.c	(original)
+++ trunk/gegl/gegl-utils.c	Fri Apr 18 22:28:05 2008
@@ -293,14 +293,13 @@
 
 #define GEGL_ALIGN 16
 
+#if 0
 void *
 gegl_malloc (gsize size);
 
 /* utility call that makes sure allocations are 16 byte aligned.
  * making RGBA float buffers have aligned access for pixels.
- */ 
-void *
-gegl_malloc (gsize size)
+ */ void * gegl_malloc (gsize size)
 {
   gint   off;
   gint   i;
@@ -331,3 +330,35 @@
    p--;
   g_free (p);
 }
+#endif
+
+
+gpointer
+gegl_malloc (gsize size);
+
+/* utility call that makes sure allocations are 16 byte aligned.
+ * making RGBA float buffers have aligned access for pixels.
+ */ 
+gpointer gegl_malloc (gsize size)
+{
+  gchar *mem;
+  gchar *ret;
+  gint   offset;
+
+  mem    = g_malloc (size + GEGL_ALIGN + sizeof(gpointer));
+  offset = GEGL_ALIGN - (((guint)mem) + sizeof(gpointer)) % GEGL_ALIGN;
+  ret    = (gpointer)(mem + sizeof(gpointer) + offset);
+
+  /* store the real malloc one pointer in front of this malloc */
+  *(gpointer*)(ret-sizeof(gpointer))=mem;
+  return (gpointer) ret;
+}
+
+void
+gegl_free (gpointer buf);
+void
+gegl_free (gpointer buf)
+{
+  g_assert (buf);
+  g_free (*((gpointer*)buf -1));
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]