Revision: 54551
http://brlcad.svn.sourceforge.net/brlcad/?rev=54551&view=rev
Author: brlcad
Date: 2013-03-07 05:18:57 +0000 (Thu, 07 Mar 2013)
Log Message:
-----------
expand docs on how BU_GET()+BU_PUT() are supposed to be used, add new
BU_ALLOC() convenience macro that basically is the same as the old
BU_GETSTRUCT() macro without being specific to structs -- it just saves some of
the typing repetition when allocating a single struct. most of the existing
BU_GET() calls will get converted to BU_ALLOC() unless a BU_PUT() pairing is
obvious/trivial or if it's performance-critical code.
Modified Paths:
--------------
brlcad/trunk/include/bu.h
Modified: brlcad/trunk/include/bu.h
===================================================================
--- brlcad/trunk/include/bu.h 2013-03-07 03:05:25 UTC (rev 54550)
+++ brlcad/trunk/include/bu.h 2013-03-07 05:18:57 UTC (rev 54551)
@@ -236,10 +236,16 @@
/**
- * Handy dynamic memory allocator macro. Allocated memory is
- * automatically initialized to zero and guaranteed (else bu_bomb()).
+ * Fast dynamic memory allocation macro for small allocations. Memory
+ * is automatically initialized to zero and, similar to bu_calloc(),
+ * is guaranteed to return non-NULL (or bu_bomb()).
*
- * Memory acquired with BU_GET() should be returned with BU_PUT().
+ * Memory acquired with BU_GET() should be returned with BU_PUT(), NOT
+ * with bu_free().
+ *
+ * Use BU_ALLOC() for dynamically allocating single structures that
+ * are relatively large, infrequently allocated, or otherwise don't
+ * need to be fast.
*/
#define BU_GET(_ptr, _type) _ptr = (_type *)bu_calloc(1, sizeof(_type), #_type
" (BU_GET) " BU_FLSTR)
@@ -248,11 +254,19 @@
* first byte zero'd for sanity (and potential early detection of
* double-free crashing code) and the pointer is set to NULL.
*
- * Memory acquired with BU_GET() should be returned with BU_PUT().
+ * Memory acquired with bu_malloc()/bu_calloc() should be returned
+ * with bu_free(), NOT with BU_PUT().
*/
#define BU_PUT(_ptr, _type) *(uint8_t *)(_ptr) = /*zap*/ 0; bu_free(_ptr,
#_type " (BU_PUT) " BU_FLSTR); _ptr = NULL
+/**
+ * Convenience macro for allocating a single structure on the heap.
+ * Not intended for performance-critical code. Release memory
+ * acquired with bu_free().
+ */
+#define BU_ALLOC(_ptr, _type) _ptr = (_type *)bu_calloc(1, sizeof(_type),
#_type " (BU_ALLOC) " BU_FLSTR)
+
/**
* @def BU_ASSERT(eqn)
* Quick and easy macros to generate an informative error message and
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
endpoint security space. For insight on selecting the right partner to
tackle endpoint security challenges, access the full report.
http://p.sf.net/sfu/symantec-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits