HL-HDF
hlhdf_alloc.h File Reference

Allocation routines for keeping track on memory. More...

#include <stdlib.h>

Go to the source code of this file.

Macros

#define HLHDF_MALLOC(sz)   malloc(sz)
 malloc
 
#define HLHDF_CALLOC(npts, sz)   calloc(npts, sz)
 calloc
 
#define HLHDF_REALLOC(ptr, sz)   realloc(ptr, sz)
 realloc
 
#define HLHDF_STRDUP(x)   strdup(x)
 strdup
 
#define HLHDF_FREE(x)   if (x != NULL) {free(x);x=NULL;}
 Frees the pointer if != NULL.
 

Functions

void * hlhdf_alloc_malloc (const char *filename, int lineno, size_t sz)
 Allocates memory and keeps track on if it is released, overwritten and similar.
 
void * hlhdf_alloc_calloc (const char *filename, int lineno, size_t npts, size_t sz)
 Same as calloc but debugged.
 
void * hlhdf_alloc_realloc (const char *filename, int lineno, void *ptr, size_t sz)
 Same as realloc but debugged.
 
char * hlhdf_alloc_strdup (const char *filename, int lineno, const char *str)
 Same as strdup but debugged.
 
void hlhdf_alloc_free (const char *filename, int lineno, void *ptr)
 Releases the memory.
 
void hlhdf_alloc_dump_heap (void)
 Dumps all blocks that not has been released.
 
void hlhdf_alloc_print_statistics (void)
 Prints the statistics for the heap.
 

Detailed Description

Allocation routines for keeping track on memory.

Author
Anders Henja (Swedish Meteorological and Hydrological Institute, SMHI)
Date
2009-06-26

Macro Definition Documentation

◆ HLHDF_CALLOC

#define HLHDF_CALLOC ( npts,
sz )   calloc(npts, sz)

calloc

◆ HLHDF_FREE

#define HLHDF_FREE ( x)    if (x != NULL) {free(x);x=NULL;}

Frees the pointer if != NULL.

◆ HLHDF_MALLOC

#define HLHDF_MALLOC ( sz)    malloc(sz)

malloc

◆ HLHDF_REALLOC

#define HLHDF_REALLOC ( ptr,
sz )   realloc(ptr, sz)

realloc

◆ HLHDF_STRDUP

#define HLHDF_STRDUP ( x)    strdup(x)

strdup

Function Documentation

◆ hlhdf_alloc_calloc()

void * hlhdf_alloc_calloc ( const char * filename,
int lineno,
size_t npts,
size_t sz )

Same as calloc but debugged.

Parameters
[in]filenamethe name of the file the allocation occurs in
[in]linenothe linenumber
[in]nptsnumber of points
[in]szthe number of bytes to be allocated

◆ hlhdf_alloc_dump_heap()

void hlhdf_alloc_dump_heap ( void )

Dumps all blocks that not has been released.

◆ hlhdf_alloc_free()

void hlhdf_alloc_free ( const char * filename,
int lineno,
void * ptr )

Releases the memory.

Parameters
[in]filenamethe name of the file the allocation occurs in
[in]linenothe linenumber
[in]ptrthe pointer that should be freed

◆ hlhdf_alloc_malloc()

void * hlhdf_alloc_malloc ( const char * filename,
int lineno,
size_t sz )

Allocates memory and keeps track on if it is released, overwritten and similar.

Parameters
[in]filenamethe name of the file the allocation occurs in
[in]linenothe linenumber
[in]szthe number of bytes to be allocated

◆ hlhdf_alloc_print_statistics()

void hlhdf_alloc_print_statistics ( void )

Prints the statistics for the heap.

◆ hlhdf_alloc_realloc()

void * hlhdf_alloc_realloc ( const char * filename,
int lineno,
void * ptr,
size_t sz )

Same as realloc but debugged.

Parameters
[in]filenamethe name of the file the allocation occurs in
[in]linenothe linenumber
[in]ptrthe original pointer
[in]szthe number of bytes to be allocated

◆ hlhdf_alloc_strdup()

char * hlhdf_alloc_strdup ( const char * filename,
int lineno,
const char * str )

Same as strdup but debugged.

Parameters
[in]filenamethe name of the file the allocation occurs in
[in]linenothe linenumber
[in]strthe number of bytes to be allocated