LAL  7.5.0.1-bede9b2
LALMalloc.c File Reference

Prototypes

void *() XLALMalloc (size_t n)
 
void * XLALMallocLong (size_t n, const char *file, int line)
 
void *() XLALCalloc (size_t m, size_t n)
 
void * XLALCallocLong (size_t m, size_t n, const char *file, int line)
 
void *() XLALRealloc (void *p, size_t n)
 
void * XLALReallocLong (void *p, size_t n, const char *file, int line)
 
void() XLALFree (void *p)
 
void XLALFreeLong (void *p, const char *file UNUSED, int line UNUSED)
 
static UNUSED int AllocHashTblResize (void)
 
static UNUSED struct allocNodeAllocHashTblFind (struct allocNode *x)
 
static UNUSED int AllocHashTblAdd (struct allocNode *x)
 
static UNUSED struct allocNodeAllocHashTblExtract (struct allocNode *x)
 
static UNUSED int CheckAllocList (void)
 
static UNUSED struct allocNodeFindAlloc (void *p)
 
static void * PadAlloc (size_t *p, size_t n, int keep, const char *func, const char *file, int line)
 
static void * UnPadAlloc (void *p, int keep, const char *func, const char *file, int line)
 
static void * PushAlloc (void *p, size_t n, const char *file, int line)
 
static void * PopAlloc (void *p, const char *func, const char *file, int line)
 
static void * ModAlloc (void *p, void *q, size_t n, const char *func, const char *file, int line)
 
void * LALMallocShort (size_t n)
 
void * LALMallocLong (size_t n, const char *file, int line)
 
void * LALCallocShort (size_t m, size_t n)
 
void * LALCallocLong (size_t m, size_t n, const char *file, int line)
 
void * LALReallocShort (void *p, size_t n)
 
void * LALReallocLong (void *q, size_t n, const char *file, const int line)
 
void LALFreeShort (void *q)
 
void LALFreeLong (void *q, const char *file, const int line)
 
void LALCheckMemoryLeaks (void)
 

Go to the source code of this file.

Data Structures

struct  allocNode
 

Macros

#define XLAL_TEST_POINTER(ptr, size)
 
#define XLAL_TEST_POINTER_LONG(ptr, size, file, line)
 
#define XLAL_TEST_POINTER_ALIGNED(ptr, size, retval)
 
#define XLAL_TEST_POINTER_ALIGNED_LONG(ptr, size, retval, file, line)
 
#define pthread_mutex_lock(pmut)
 
#define pthread_mutex_unlock(pmut)
 
#define allocsz(n)   ((lalDebugLevel & LALMEMPADBIT) ? (padFactor * (n) + prefix) : (n))
 
#define DEL   ((struct allocNode*) &hash_del)
 
#define HASHIDX(x)   ((int)( ((intptr_t)( (x)->addr )) % alloc_data_len ))
 
#define INCRIDX(i)   do { if (++(i) == alloc_data_len) { (i) = 0; } } while(0)
 
#define EQUAL(x, y)   ((x)->addr == (y)->addr)
 

Enumerations

enum  { nprefix = 2 }
 

Variables

size_t lalMallocTotal = 0
 current amount of memory allocated by process More...
 
size_t lalMallocTotalPeak = 0
 peak amount of memory allocated so far More...
 
char * lalMemDbgArgPtr = NULL
 
char * lalMemDbgRetPtr = NULL
 
char * lalMemDbgPtr = NULL
 
char * lalMemDbgUsrPtr = NULL
 
void ** lalMemDbgUsrHndl = NULL
 
int lalIsMemDbgArgPtr
 
int lalIsMemDbgRetPtr
 
int lalIsMemDbgPtr
 
static const size_t prefix = nprefix * sizeof(size_t)
 
static const size_t padFactor = 2
 
static const size_t padding = 0xDeadBeef
 
static const size_t repadding = 0xBeefDead
 
static const size_t magic = 0xABadCafe
 
static struct allocNode ** alloc_data = NULL
 
static int alloc_data_len = 0
 
static int alloc_n = 0
 
static int alloc_q = 0
 
static const void * hash_del = 0
 

Macro Definition Documentation

◆ XLAL_TEST_POINTER

#define XLAL_TEST_POINTER (   ptr,
  size 
)
Value:
if ( ! (ptr) && (size) ) \
XLAL_ERROR_NULL( XLAL_ENOMEM ); \
else (void)(0)
@ XLAL_ENOMEM
Memory allocation error.
Definition: XLALError.h:407

Definition at line 47 of file LALMalloc.c.

◆ XLAL_TEST_POINTER_LONG

#define XLAL_TEST_POINTER_LONG (   ptr,
  size,
  file,
  line 
)
Value:
if ( ! (ptr) && (size) ) \
{ \
XLALPrintError( "XLALError - %s in %s:%d", __func__, file, line ); \
XLAL_ERROR_NULL( XLAL_ENOMEM ); \
} \
else (void)(0)

Definition at line 51 of file LALMalloc.c.

◆ XLAL_TEST_POINTER_ALIGNED

#define XLAL_TEST_POINTER_ALIGNED (   ptr,
  size,
  retval 
)
Value:
if ( ! (ptr) && (size) && (retval) ) \
XLAL_ERROR_NULL( XLAL_ENOMEM ); \
else (void)(0)

Definition at line 58 of file LALMalloc.c.

◆ XLAL_TEST_POINTER_ALIGNED_LONG

#define XLAL_TEST_POINTER_ALIGNED_LONG (   ptr,
  size,
  retval,
  file,
  line 
)
Value:
if ( ! (ptr) && (size) && (retval) ) \
{ \
XLALPrintError( "XLALError - %s in %s:%d", __func__, file, line ); \
XLAL_ERROR_NULL( XLAL_ENOMEM ); \
} \
else (void)(0)

Definition at line 62 of file LALMalloc.c.

◆ pthread_mutex_lock

#define pthread_mutex_lock (   pmut)

Definition at line 237 of file LALMalloc.c.

◆ pthread_mutex_unlock

#define pthread_mutex_unlock (   pmut)

Definition at line 238 of file LALMalloc.c.

◆ allocsz

#define allocsz (   n)    ((lalDebugLevel & LALMEMPADBIT) ? (padFactor * (n) + prefix) : (n))

Definition at line 262 of file LALMalloc.c.

◆ DEL

#define DEL   ((struct allocNode*) &hash_del)

Definition at line 278 of file LALMalloc.c.

◆ HASHIDX

#define HASHIDX (   x)    ((int)( ((intptr_t)( (x)->addr )) % alloc_data_len ))

Definition at line 281 of file LALMalloc.c.

◆ INCRIDX

#define INCRIDX (   i)    do { if (++(i) == alloc_data_len) { (i) = 0; } } while(0)

Definition at line 284 of file LALMalloc.c.

◆ EQUAL

#define EQUAL (   x,
 
)    ((x)->addr == (y)->addr)

Definition at line 287 of file LALMalloc.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
nprefix 

Definition at line 255 of file LALMalloc.c.

Function Documentation

◆ XLALFreeLong()

void XLALFreeLong ( void *  p,
const char *file  UNUSED,
int line  UNUSED 
)

Definition at line 120 of file LALMalloc.c.

◆ AllocHashTblResize()

static UNUSED int AllocHashTblResize ( void  )
static

Definition at line 297 of file LALMalloc.c.

◆ AllocHashTblFind()

static UNUSED struct allocNode* AllocHashTblFind ( struct allocNode x)
static

Definition at line 324 of file LALMalloc.c.

◆ AllocHashTblAdd()

static UNUSED int AllocHashTblAdd ( struct allocNode x)
static

Definition at line 341 of file LALMalloc.c.

◆ AllocHashTblExtract()

static UNUSED struct allocNode* AllocHashTblExtract ( struct allocNode x)
static

Definition at line 362 of file LALMalloc.c.

◆ CheckAllocList()

static UNUSED int CheckAllocList ( void  )
static

Definition at line 395 of file LALMalloc.c.

◆ FindAlloc()

static UNUSED struct allocNode* FindAlloc ( void *  p)
static

Definition at line 411 of file LALMalloc.c.

◆ PadAlloc()

static void* PadAlloc ( size_t *  p,
size_t  n,
int  keep,
const char *  func,
const char *  file,
int  line 
)
static

Definition at line 418 of file LALMalloc.c.

◆ UnPadAlloc()

static void* UnPadAlloc ( void *  p,
int  keep,
const char *  func,
const char *  file,
int  line 
)
static

Definition at line 453 of file LALMalloc.c.

◆ PushAlloc()

static void* PushAlloc ( void *  p,
size_t  n,
const char *  file,
int  line 
)
static

Definition at line 534 of file LALMalloc.c.

◆ PopAlloc()

static void* PopAlloc ( void *  p,
const char *  func,
const char *  file,
int  line 
)
static

Definition at line 560 of file LALMalloc.c.

◆ ModAlloc()

static void* ModAlloc ( void *  p,
void *  q,
size_t  n,
const char *  func,
const char *  file,
int  line 
)
static

Definition at line 584 of file LALMalloc.c.

◆ LALCheckMemoryLeaks()

void LALCheckMemoryLeaks ( void  )

Definition at line 784 of file LALMalloc.c.

Variable Documentation

◆ lalMemDbgArgPtr

char* lalMemDbgArgPtr = NULL

Definition at line 245 of file LALMalloc.c.

◆ lalMemDbgRetPtr

char* lalMemDbgRetPtr = NULL

Definition at line 246 of file LALMalloc.c.

◆ lalMemDbgPtr

char* lalMemDbgPtr = NULL

Definition at line 247 of file LALMalloc.c.

◆ lalMemDbgUsrPtr

char* lalMemDbgUsrPtr = NULL

Definition at line 248 of file LALMalloc.c.

◆ lalMemDbgUsrHndl

void** lalMemDbgUsrHndl = NULL

Definition at line 249 of file LALMalloc.c.

◆ lalIsMemDbgArgPtr

int lalIsMemDbgArgPtr

Definition at line 250 of file LALMalloc.c.

◆ lalIsMemDbgRetPtr

int lalIsMemDbgRetPtr

Definition at line 251 of file LALMalloc.c.

◆ lalIsMemDbgPtr

int lalIsMemDbgPtr

Definition at line 252 of file LALMalloc.c.

◆ prefix

const size_t prefix = nprefix * sizeof(size_t)
static

Definition at line 256 of file LALMalloc.c.

◆ padFactor

const size_t padFactor = 2
static

Definition at line 257 of file LALMalloc.c.

◆ padding

const size_t padding = 0xDeadBeef
static

Definition at line 258 of file LALMalloc.c.

◆ repadding

const size_t repadding = 0xBeefDead
static

Definition at line 259 of file LALMalloc.c.

◆ magic

const size_t magic = 0xABadCafe
static

Definition at line 260 of file LALMalloc.c.

◆ alloc_data

struct allocNode ** alloc_data = NULL
static

◆ alloc_data_len

int alloc_data_len = 0
static

Definition at line 272 of file LALMalloc.c.

◆ alloc_n

int alloc_n = 0
static

Definition at line 273 of file LALMalloc.c.

◆ alloc_q

int alloc_q = 0
static

Definition at line 274 of file LALMalloc.c.

◆ hash_del

const void* hash_del = 0
static

Definition at line 277 of file LALMalloc.c.