Memory management


Modules

 Memory chunk allocer

Defines

#define di_new(struct_type, n_structs)   ((struct_type *) di_malloc (sizeof (struct_type) * (n_structs)))
#define di_new0(struct_type, n_structs)   ((struct_type *) di_malloc0 (sizeof (struct_type) * (n_structs)))
#define di_renew(struct_type, mem, n_structs)   ((struct_type *) di_realloc ((mem), sizeof (struct_type) * (n_structs)))

Functions

void * di_malloc (size_t n_bytes) __attribute__((malloc))
void * di_malloc0 (size_t n_bytes) __attribute__((malloc))
void * di_realloc (void *mem, size_t n_bytes) __attribute__((malloc))
void di_free (void *mem)

Define Documentation

#define di_new ( struct_type,
n_structs   )     ((struct_type *) di_malloc (sizeof (struct_type) * (n_structs)))

Parameters:
struct_type returned type
n_structs number of returned structs

#define di_new0 ( struct_type,
n_structs   )     ((struct_type *) di_malloc0 (sizeof (struct_type) * (n_structs)))

Parameters:
struct_type returned type
n_structs number of returned structs

#define di_renew ( struct_type,
mem,
n_structs   )     ((struct_type *) di_realloc ((mem), sizeof (struct_type) * (n_structs)))

Parameters:
struct_type returned type
mem current memory pointer
n_structs number of returned structs


Function Documentation

void di_free ( void *  mem  ) 

Free memory

Parameters:
mem memory
00064 {
00065   free (mem);
00066 }

void* di_malloc ( size_t  n_bytes  ) 

Allocate memory

Parameters:
n_bytes size in bytes
Postcondition:
never returns NULL
00033 {
00034   void *mem;
00035 
00036   mem = malloc (n_bytes);
00037 
00038   if (!mem)
00039     di_error ("%s: failed to allocate %zu bytes", DI_STRLOC, n_bytes);
00040   return mem;
00041 }

void* di_malloc0 ( size_t  n_bytes  ) 

Allocate cleared memory

Parameters:
n_bytes size in bytes
Postcondition:
never returns NULL
00044 {
00045   void *mem;
00046 
00047   mem = calloc (1, n_bytes);
00048 
00049   if (!mem)
00050     di_error ("%s: failed to allocate %zu bytes", DI_STRLOC, n_bytes);
00051   return mem;
00052 }

void* di_realloc ( void *  mem,
size_t  n_bytes 
)

Reallocate memory

Parameters:
mem memory
n_bytes size in bytes
Postcondition:
never returns NULL
00055 {
00056   mem = realloc (mem, n_bytes);
00057 
00058   if (!mem)
00059     di_error ("%s: failed to allocate %zu bytes", DI_STRLOC, n_bytes);
00060   return mem;
00061 }


Generated on Sat Sep 29 08:45:16 2007 for libdebian-installer by  doxygen 1.5.1