Home2L - C/C++ API  v1.2-2-ga4fe (2023-04-15)
Smart Tools for a Private Home
Heap

Description

Type-safe and null-pointer-aware heap operations.

Collaboration diagram for Heap:

C-style Allocation ...

#define MALLOC(T, N)   (T*) malloc (sizeof (T) * (N))
 Allocate an array of N objects of type T (type-safe)
 
#define REALLOC(T, P, N)   (T*) realloc (P, sizeof (T) * (N))
 Reallocate an array of N objects of type T (type-safe)
 
#define SETP(P, X)   { if (P) free (P); P = (X); }
 Replace P with a new object/array, eventually free'ing the old one.
 
#define FREEP(P)   SETP(P, NULL)
 Free object/array P and set P = NULL, but only if P was != NULL.
 

C++-style Allocation ...

#define SETO(O, X)   { if (O) delete O; O = (X); }
 Replace O with a new object, eventually deleting the old one.
 
#define FREEO(O)   SETO(O, NULL)
 Free object O, but only if O != NULL
 
#define SETA(A, X)   { if (A) delete [] A; A = (X); }
 Replace A with a new array, eventually deleting the old one.
 
#define FREEA(A)   SETA(A, NULL)
 Free array A, but only if A != NULL