Loading...
Searching...
No Matches
Memory Management Utilities

## Functions

void * | cpl_calloc (size_t natoms, size_t nbytes)
| Allocate memory for natoms elements of size size.
void | cpl_free (void *memblk)
| Memory block deallocation.
void * | cpl_malloc (size_t nbytes)
| Allocate nbytes bytes.
void | cpl_memory_dump (void)
| Display the memory status.
int | cpl_memory_is_empty (void)
| Tell if there is some memory allocated.
void * | cpl_realloc (void *memblk, size_t nbytes)
| Change the size of a memory block.
char * | cpl_sprintf (const char *format,...)
| Create a string and fill it in an sprintf()-like manner.
char * | cpl_strdup (const char *string)
| Duplicate a string.
char * | cpl_vsprintf (const char *format, va_list arglist)
| Create a string and fill it in an vsprintf()-like manner.

## Detailed Description

This module provides the CPL memory management utilities.

## Function Documentation

## cpl_calloc()

void * cpl_calloc | ( | size_t | natoms,
|  | size_t | nbytes )

Allocate memory for natoms elements of size size.

Parameters

  natoms | Number of atomic elements.
  nbytes | Element size in bytes.

Returns
  Pointer to the allocated memory block.

The function allocates memory suitable for storage of natoms elements of size nbytes bytes. The allocated memory is cleared, i.e. the value 0 is written to each single byte.

Note
  If the memory subsytem has not been initialised before calling this function, the program execution is stopped printing a message to the error channel showing the current code position.

Referenced by cpl_apertures_sort_by_flux(), cpl_apertures_sort_by_max(), cpl_apertures_sort_by_npix(), cpl_array_cast(), cpl_array_dump(), cpl_array_new(), cpl_array_wrap_cplsize(), cpl_array_wrap_double(), cpl_array_wrap_double_complex(), cpl_array_wrap_float(), cpl_array_wrap_float_complex(), cpl_array_wrap_int(), cpl_array_wrap_long(), cpl_array_wrap_long_long(), cpl_array_wrap_string(), cpl_image_fft(), cpl_imagelist_new(), cpl_mask_new(), cpl_matrix_new(), cpl_matrix_sort_columns(), cpl_matrix_sort_rows(), cpl_polynomial_extract(), cpl_ppm_match_positions(), cpl_table_and_selected_window(), cpl_table_dump(), cpl_table_new(), cpl_table_or_selected_window(), cpl_table_select_row(), cpl_wcs_platesol(), and cpl_wlcalib_slitmodel_new().

## cpl_free()

void cpl_free | ( | void * | memblk | ) |

Memory block deallocation.

Returns
  Nothing.

Deallocates a memory block previously allocated by any of the CPL allocator functions.

See also
  cpl_malloc(), cpl_calloc()

Referenced by cpl_apertures_delete(), cpl_apertures_sort_by_flux(), cpl_apertures_sort_by_max(), cpl_apertures_sort_by_npix(), cpl_array_cast(), cpl_array_delete(), cpl_array_dump(), cpl_array_unwrap(), cpl_bivector_delete(), cpl_bivector_unwrap_vectors(), cpl_dfs_setup_product_header(), cpl_fit_image_gaussian(), cpl_image_cast(), cpl_image_delete(), cpl_image_divide_create(), cpl_image_fft(), cpl_image_labelise_mask_create(), cpl_image_move(), cpl_image_unwrap(), cpl_imagelist_cast(), cpl_imagelist_unwrap(), cpl_mask_delete(), cpl_mask_move(), cpl_mask_save(), cpl_mask_unwrap(), cpl_matrix_delete(), cpl_matrix_get_median(), cpl_matrix_resize(), cpl_matrix_shift(), cpl_matrix_sort_columns(), cpl_matrix_sort_rows(), cpl_matrix_unwrap(), cpl_msg_progress(), cpl_plot_bivector(), cpl_plot_bivectors(), cpl_plot_columns(), cpl_plot_image(), cpl_plot_image_col(), cpl_plot_image_row(), cpl_plot_mask(), cpl_plot_vector(), cpl_plot_vectors(), cpl_polynomial_delete(), cpl_polynomial_dump(), cpl_polynomial_extract(), cpl_polynomial_multiply(), cpl_ppm_match_positions(), cpl_propertylist_save(), cpl_stats_delete(), cpl_stats_new_from_image_window(), cpl_table_and_selected_window(), cpl_table_delete(), cpl_table_dump(), cpl_table_or_selected_window(), cpl_table_select_all(), cpl_table_select_row(), cpl_table_sort(), cpl_table_unselect_all(), cpl_table_unselect_row(), cpl_vector_cycle(), cpl_vector_delete(), cpl_vector_fit_gaussian(), cpl_vector_get_median_const(), cpl_vector_load(), cpl_vector_save(), cpl_vector_unwrap(), cpl_wcs_delete(), cpl_wcs_platesol(), and cpl_wlcalib_slitmodel_delete().

## cpl_malloc()

void * cpl_malloc | ( | size_t | nbytes | ) |

Allocate nbytes bytes.

Parameters

  nbytes | Number of bytes.

Returns
  Pointer to the allocated memory block.

The function allocates nbytes bytes of memory. The allocated memory is not cleared.

Note
  If the memory subsytem has not been initialised before calling this function, the program execution is stopped printing a message to the error channel showing the current code position.

References cpl_malloc().

Referenced by cpl_apertures_sort_by_flux(), cpl_apertures_sort_by_max(), cpl_apertures_sort_by_npix(), cpl_array_dump(), cpl_bivector_duplicate(), cpl_bivector_new(), cpl_bivector_wrap_vectors(), cpl_fit_image_gaussian(), cpl_fit_imagelist_polynomial_window(), cpl_geom_img_offset_saa(), cpl_image_cast(), cpl_image_divide_create(), cpl_image_duplicate(), cpl_image_labelise_mask_create(), cpl_image_move(), cpl_image_new_from_mask(), cpl_imagelist_cast(), cpl_malloc(), cpl_mask_collapse_create(), cpl_mask_duplicate(), cpl_mask_move(), cpl_mask_wrap(), cpl_matrix_duplicate(), cpl_matrix_extract(), cpl_matrix_extract_diagonal(), cpl_matrix_get_determinant(), cpl_matrix_get_median(), cpl_matrix_invert_create(), cpl_matrix_new(), cpl_matrix_product_create(), cpl_matrix_shift(), cpl_matrix_solve(), cpl_matrix_sort_columns(), cpl_matrix_sort_rows(), cpl_matrix_transpose_create(), cpl_matrix_wrap(), cpl_plot_bivectors(), cpl_plot_columns(), cpl_plot_image(), cpl_plot_mask(), cpl_plot_vectors(), cpl_polynomial_dump(), cpl_polynomial_multiply(), cpl_ppm_match_positions(), cpl_stats_new_from_image_window(), cpl_table_dump(), cpl_table_duplicate(), cpl_table_sort(), cpl_table_unselect_row(), cpl_vector_cycle(), cpl_vector_fill_polynomial_fit_residual(), cpl_vector_fit_gaussian(), cpl_vector_get_median_const(), cpl_vector_load(), cpl_vector_new(), cpl_vector_wrap(), and cpl_wcs_platesol().

## cpl_memory_dump()

void cpl_memory_dump | ( | void |  | ) |

Display the memory status.

Referenced by cpl_test_end().

## cpl_memory_is_empty()

int cpl_memory_is_empty | ( | void |  | ) |

Tell if there is some memory allocated.

Returns
  -1 if the model is off, 1 if it is empty, 0 otherwise

Referenced by cpl_test_end().

## cpl_realloc()

void * cpl_realloc | ( | void * | memblk,
|  | size_t | nbytes )

Change the size of a memory block.

Parameters

  memblk | Pointer to the memory to re-allocate.
  nbytes | New memory block size in bytes.

Returns
  Pointer to the allocated memory block.

The function changes the size of an already allocated memory block memblk to the new size nbytes bytes. The contents is unchanged to the minimum of old and new size; newly allocated memory is not initialized. If memblk is `NULL` the call to cpl_realloc() is equivalent to cpl_malloc(), and if nbytes is 0 the call is equivalent to cpl_free(). Unless memblk is `NULL`, it must have been returned by a previous call to cpl_malloc(), cpl_calloc(), or cpl_realloc().

Note
  - The returned memory block returned on successfull allocation may not be the same as the one pointed to by memblk. Existing references pointing to locations within the original memory block might be invalidated!
  - If the memory subsytem has not been initialised before calling this function, the program execution is stopped printing a message to the error channel showing the current code position.

See also
  cpl_malloc(), cpl_calloc()

Referenced by cpl_imagelist_set(), cpl_matrix_erase_columns(), cpl_matrix_erase_rows(), and cpl_vector_set_size().

## cpl_sprintf()

char * cpl_sprintf | ( | const char * | format,
|  |  | ... )

Create a string and fill it in an sprintf()-like manner.

Parameters

  format | The format string
  ... | Variable argument list for format

Returns
  The created string or NULL on error

Note
  The created string must be deallocated with cpl_free()

See also
  cpl_vsprintf()

The allocated memory is exactly what is needed to hold the string.

Errors

  CPL_ERROR_NULL_INPUT | The format string is NULL.
  CPL_ERROR_ILLEGAL_INPUT | The format string has an invalid format.

Example of usage (note how strlen() is not needed to get the string length):

int error;
int length;
char * cp_cmd = cpl_sprintf("cp %s %s/%s%n", long_file, new_dir,
new_file, &length);
assert( cp_cmd != NULL);
assert( length == (int)strlen(cp_cmd));
error = system(cp_cmd);
assert(!error);
cpl_free(cp_cmd);
cpl_sprintf
char * cpl_sprintf(const char *format,...)
Create a string and fill it in an sprintf()-like manner.
Definition cpl_memory.c:386
cpl_free
void cpl_free(void *memblk)
Memory block deallocation.
Definition cpl_memory.c:224

References cpl_ensure, cpl_error_get_code(), CPL_ERROR_NULL_INPUT, and cpl_vsprintf().

Referenced by cpl_array_dump(), cpl_dfs_setup_product_header(), cpl_mask_save(), cpl_msg_progress(), cpl_plot_bivector(), cpl_plot_bivectors(), cpl_plot_columns(), cpl_plot_image(), cpl_plot_image_col(), cpl_plot_image_row(), cpl_plot_mask(), cpl_plot_vector(), cpl_plot_vectors(), cpl_plugin_get_version_string(), cpl_propertylist_save(), cpl_table_dump(), and cpl_vector_save().

## cpl_strdup()

char * cpl_strdup | ( | const char * | string | ) |

Duplicate a string.

Parameters

  string | String to be duplicated.

Returns
  Newly allocated copy of the original string.

Duplicates the input string string. The newly allocated copy returned to the caller can be deallocated using cpl_free().

See also
  cpl_free()

Referenced by cpl_dfs_setup_product_header().

## cpl_vsprintf()

char * cpl_vsprintf | ( | const char * | format,
|  | va_list | arglist )

Create a string and fill it in an vsprintf()-like manner.

Parameters

  format | The format string
  arglist | The argument list for the format

Returns
  The created string or NULL on error

Note
  The created string must be deallocated with cpl_free()

See also
  vsprintf()

The allocated memory is exactly what is needed to hold the string.

Errors

  CPL_ERROR_NULL_INPUT | The format string is NULL.
  CPL_ERROR_ILLEGAL_INPUT | The format string has an invalid format.

References cpl_ensure, CPL_ERROR_ILLEGAL_INPUT, and CPL_ERROR_NULL_INPUT.

Referenced by cpl_sprintf().