Next: , Previous: , Up: system memory   [Contents][Index]


7.1.3 Guarded allocation: malloc()

To allocate memory using a clean handler with a guarded function, we can do:

cce_location_t          L[1];
cce_clean_handler_t     P_H[1];

if (cce_location(L)) {
  cce_run_catch_handlers_final(L);
} else {
  void *  P = cce_sys_malloc_guarded(L, P_H, 1024);

  /* Do something with P. */
  cce_run_body_handlers(L);
}

while to use an error handler we can do:

cce_location_t          L[1];
cce_error_handler_t     P_H[1];

if (cce_location(L)) {
  cce_run_catch_handlers_final(L);
} else {
  void *  P = cce_sys_malloc_guarded(L, P_H, 1024);

  /* Do something with P. */
  cce_run_body_handlers(L);
}
Function: void * cce_sys_malloc_guarded_clean (cce_destination_t L, cce_clean_handler_t * P_H, size_t size)
Function: void * cce_sys_malloc_guarded_error (cce_destination_t L, cce_error_handler_t * P_H, size_t size)

Like cce_sys_malloc(), but register the resulting pointer in the handler referenced by P_H.

Preprocessor Macro: void * cce_sys_malloc_guarded (cce_destination_t L, cce_clean_handler_t * P_H, size_t size)
Preprocessor Macro: void * cce_sys_malloc_guarded (cce_destination_t L, cce_error_handler_t * P_H, size_t size)

This preprocessor macro uses _Generic to dispatch the call according to the type of the pointer P_H; if the type is:

cce_clean_handler_t

The macro expands into a call to cce_sys_malloc_guarded_clean().

cce_error_handler_t

The macro expands into a call to cce_sys_malloc_guarded_error().


Next: , Previous: , Up: system memory   [Contents][Index]

This document describes version 0.9.0-devel.3 of CCExceptions.