Hitmap 1.3
 All Data Structures Namespaces Files Functions Variables Typedefs Friends Macros Groups Pages
Macros
hit_allocP.h File Reference

Hitmap functions to allocate memory. More...

#include <stdlib.h>
#include "hit_error.h"
Include dependency graph for hit_allocP.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define hit_vmalloc(ptr, size)
 
#define hit_malloc(ptr, type, nmemb)
 
#define hit_calloc(ptr, type, nmemb)
 
#define hit_realloc(ptr, type, nmemb)
 
#define hit_free(ptr)
 

Detailed Description

Hitmap functions to allocate memory.

This is a set of macro-functions that allocate memory and check the result. They print an error message if the allocate routine fails. This is an interface for Hitmap developers.

These macros include a cast of the result pointers for compatibility with C++. In C langauge the cast is not needed because the stdlib malloc function should return a void pointer.

Version
1.1
Author
Arturo Gonzalez-Escribano
Javier Fresno Bausela
Date
Aug 2015

Definition in file hit_allocP.h.

Macro Definition Documentation

#define hit_calloc (   ptr,
  type,
  nmemb 
)
Value:
{ \
ptr = (type *)calloc( (size_t)(nmemb), sizeof(type)); \
if(ptr == NULL) hit_errInternal(__func__,"Memory allocation request failed","",__FILE__,__LINE__) \
}
#define hit_errInternal(routine, text, extraParam, file, numLine)
Definition: hit_error.h:63

Allocate and initialize to zero an array of elements of a given type.

It allocates a memory block of nmemb elements of the chosen type. It initializes the elements using the calloc(3) function.

Version
1.1
Author
Arturo Gonzalez-Escribano
Javier Fresno Bausela
Parameters
[out]ptrPointer to the allocated memory.
[in]typeType of the elements of the array.
[in]nmembNumber of elements to allocate.

Definition at line 114 of file hit_allocP.h.

#define hit_free (   ptr)
Value:
{ \
free(ptr); \
ptr = NULL; \
}

Free a previous allocated block of memory.

This function frees a block of memory previously allocated and pointed by ptr.

Version
2.0
Author
Arturo Gonzalez-Escribano
Javier Fresno Bausela
Parameters
[in,out]ptrPointer to the allocated memory.

Definition at line 152 of file hit_allocP.h.

#define hit_malloc (   ptr,
  type,
  nmemb 
)
Value:
{ \
ptr = (type *)malloc(sizeof(type)* (size_t)(nmemb)); \
if(ptr == NULL) hit_errInternal(__func__,"Memory allocation request failed","",__FILE__,__LINE__) \
}
#define hit_errInternal(routine, text, extraParam, file, numLine)
Definition: hit_error.h:63

Allocate an array of elements of a given type.

It allocates a memory block of nmemb elements of the chosen type. It does not initialize the elements to a any predefined value.

Version
1.1
Author
Arturo Gonzalez-Escribano
Javier Fresno Bausela
Parameters
[out]ptrPointer to the allocated memory.
[in]typeType of the elements of the array.
[in]nmembNumber of elements to allocate.

Definition at line 93 of file hit_allocP.h.

#define hit_realloc (   ptr,
  type,
  nmemb 
)
Value:
{ \
ptr = (type *)realloc(ptr, sizeof(type)* (size_t)(nmemb)); \
if(ptr == NULL) hit_errInternal(__func__,"Memory rellocation request failed","",__FILE__,__LINE__) \
}
#define hit_errInternal(routine, text, extraParam, file, numLine)
Definition: hit_error.h:63

Change the number of elements of an array.

It changes the number of elements of an allocated array of a given type, using the reallocate(3) function. The size change may imply a reallocation of the whole array.

Version
1.1
Author
Arturo Gonzalez-Escribano
Javier Fresno Bausela
Parameters
[out]ptrPointer to the reallocated memory.
[in]typeType of the elements of the array.
[in]nmembNew number of elements in the array.

Definition at line 134 of file hit_allocP.h.

#define hit_vmalloc (   ptr,
  size 
)
Value:
{ \
ptr = (void *)malloc((size_t)(size)); \
if(ptr == NULL) hit_errInternal(__func__,"Memory allocation request failed","",__FILE__,__LINE__) \
}
int size[2]
Definition: SWcommon.c:57
#define hit_errInternal(routine, text, extraParam, file, numLine)
Definition: hit_error.h:63

Allocate memory.

It allocates a memory block of size bytes, without a specific type.

Version
1.0
Author
Arturo Gonzalez-Escribano
Parameters
[out]ptrPointer to the allocated memory.
[in]sizeTotal size of the allocated memory.

Definition at line 72 of file hit_allocP.h.