[MOAB-dev] [Itaps-users] [PATCH 1/2] iMesh_MOAB: do not allocate new memory for count=0 items

Mark Miller miller86 at llnl.gov
Fri Jun 10 14:06:37 CDT 2011


On Fri, 2011-06-10 at 11:44, Jed Brown wrote:
> There is a trivial fix for this: set ptr=0 before calling the
> function.

I have wound up defining special macros for ITAPS interfaces that handle
the (pointer, asize, osize) trio of args more conveniently in declaring
them (which also incidentally sets pointer to zero), in passing them in
function calls as a single unit, rather than laboriously spelling out
each arg and in cleaning them up (freeing).

// Macro to simplify declaration and allocation of an iMesh 'array'
#define IMESH_ADEFN(TN,ON,N)                    \
    TN* ON = (TN*) malloc(N * sizeof(TN));      \
    int ON ## _allocated = N;                   \
    int ON ## _size = N;

// Macro to simplify declaration of of an empty iMesh 'array'
#define IMESH_ADEF(TN,ON)               \
    TN* ON = 0;                         \
    int ON ## _allocated = 0;           \
    int ON ## _size = 0;

// Macro to simplify passing of an iMesh 'array' to a function
#define IMESH_AARG(ON) &ON, &ON ## _allocated, &ON ## _size

// Macro to free an iMesh 'array'
#define IMESH_AFREE(ON)                 \
    if (ON) free(ON);                   \
    ON = 0;				\
    ON ## _allocated = 0;               \
    ON ## _size = 0;

-- 
Mark C. Miller, Lawrence Livermore National Laboratory
================!!LLNL BUSINESS ONLY!!================
miller86 at llnl.gov      urgent: miller86 at pager.llnl.gov
T:8-6 (925)-423-5901    M/W/Th:7-12,2-7 (530)-753-8511



More information about the moab-dev mailing list