Di_mem

## Macros

#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)

## Detailed Description

## Macro Definition Documentation

## di_new

#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

## di_new0

#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

## di_renew

#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

## di_free()

void di_free | ( | void * | mem | ) |

Free memory

Parameters

  mem | memory

{
free (mem);
}

Referenced by di_list_destroy(), di_list_free(), di_packages_free(), di_release_free(), di_slist_destroy(), di_slist_free(), and di_tree_destroy().

## di_malloc()

void* di_malloc | ( | size_t | n_bytes | ) |

Allocate memory

Parameters

  n_bytes | size in bytes

Postcondition
  never returns NULL

{
void *mem;
mem = malloc (n_bytes);
if (!mem)
di_error ("%s: failed to allocate %zu bytes", DI_STRLOC, n_bytes);
return mem;
}
di_error
#define di_error(format...)
Definition: log.h:55

References di_error.

Referenced by di_mem_chunk_alloc().

## di_malloc0()

void* di_malloc0 | ( | size_t | n_bytes | ) |

Allocate cleared memory

Parameters

  n_bytes | size in bytes

Postcondition
  never returns NULL

{
void *mem;
mem = calloc (1, n_bytes);
if (!mem)
di_error ("%s: failed to allocate %zu bytes", DI_STRLOC, n_bytes);
return mem;
}

References di_error.

## di_realloc()

void* di_realloc | ( | void * | mem,
|  | size_t | n_bytes
| ) |  |

Reallocate memory

Parameters

  mem | memory
  n_bytes | size in bytes

Postcondition
  never returns NULL

{
mem = realloc (mem, n_bytes);
if (!mem)
di_error ("%s: failed to allocate %zu bytes", DI_STRLOC, n_bytes);
return mem;
}

References di_error.