Revision: 57073
http://sourceforge.net/p/brlcad/code/57073
Author: brlcad
Date: 2013-08-22 19:25:33 +0000 (Thu, 22 Aug 2013)
Log Message:
-----------
utilize posix_memalign() for allocations, starting with an ultra-conservative 8
byte alignment while more testing is performed. clean up some misplaced
comments while we're at it.
Modified Paths:
--------------
brlcad/trunk/src/libbu/malloc.c
Modified: brlcad/trunk/src/libbu/malloc.c
===================================================================
--- brlcad/trunk/src/libbu/malloc.c 2013-08-22 18:47:37 UTC (rev 57072)
+++ brlcad/trunk/src/libbu/malloc.c 2013-08-22 19:25:33 UTC (rev 57073)
@@ -185,7 +185,7 @@
HIDDEN genptr_t
alloc(alloc_t type, size_t cnt, size_t sz, const char *str)
{
- register genptr_t ptr = 0;
+ genptr_t ptr = 0;
register size_t size = sz;
const size_t MINSIZE = sizeof(uint32_t) > sizeof(intptr_t) ?
sizeof(uint32_t) : sizeof(intptr_t);
@@ -214,6 +214,9 @@
size = MINSIZE;
}
+ /* if we're debugging, we need a slightly larger allocation size
+ * for debug tracking.
+ */
if (UNLIKELY(bu_debug&BU_DEBUG_MEM_CHECK)) {
/* Pad, plus full uint32_t for magic number */
size = (size + 2*sizeof(uint32_t) - 1) & (~(sizeof(uint32_t) - 1));
@@ -225,26 +228,33 @@
bu_semaphore_acquire(BU_SEM_SYSCALL);
#endif
+/* align allocations to what address multiple */
+#define ALIGN 8
+
switch (type) {
case MALLOC:
+#ifdef HAVE_POSIX_MEMALIGN
+ if (posix_memalign(&ptr, ALIGN, cnt*size))
+ ptr = NULL;
+#else
ptr = malloc(cnt*size);
+#endif
break;
case CALLOC:
- /* if we're debugging, we need a slightly larger
- * allocation size for debug tracking.
- */
- if (UNLIKELY(bu_debug&(BU_DEBUG_MEM_CHECK|BU_DEBUG_MEM_QCHECK))) {
- ptr = malloc(cnt*size);
+#ifdef HAVE_POSIX_MEMALIGN
+ if (posix_memalign(&ptr, ALIGN, cnt*size))
+ ptr = NULL;
+ else
memset(ptr, 0, cnt*size);
- } else {
- ptr = calloc(cnt, size);
- }
+#else
+ ptr = calloc(cnt, size);
+#endif
break;
default:
bu_bomb("ERROR: alloc with unknown type\n");
}
- if (UNLIKELY(ptr==(char *)0 || bu_debug&BU_DEBUG_MEM_LOG)) {
+ if (UNLIKELY(ptr==NULL || bu_debug&BU_DEBUG_MEM_LOG)) {
fprintf(stderr, "NULL malloc(%llu) %s\n", (unsigned long
long)(cnt*size), str);
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Introducing Performance Central, a new site from SourceForge and
AppDynamics. Performance Central is your source for news, insights,
analysis and resources for efficient Application Performance Management.
Visit us today!
http://pubads.g.doubleclick.net/gampad/clk?id=48897511&iu=/4140/ostg.clktrk
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits