JasPer: Memory Allocation

JasPer 4.2.1 |

Loading...
Searching...
No Matches
Classes | Typedefs | Functions
Memory Allocation

Memory Allocation. More...

## Classes
struct | jas_allocator_s
| A memory allocator. More...
struct | jas_std_allocator_t
| The standard library allocator (i.e., a wrapper for malloc and friends). More...

## Typedefs
typedef struct jas_allocator_s | jas_allocator_t
| A memory allocator.

## Functions
JAS_EXPORT void * | jas_malloc (size_t size)
| Allocate memory.
JAS_EXPORT void | jas_free (void *ptr)
| Free memory.
JAS_EXPORT void * | jas_realloc (void *ptr, size_t size)
| Resize a block of allocated memory.
JAS_EXPORT void * | jas_calloc (size_t num_elements, size_t element_size)
| Allocate a block of memory and initialize the contents to zero.
JAS_EXPORT void * | jas_alloc2 (size_t num_elements, size_t element_size)
| Allocate array (with overflow checking).
JAS_EXPORT void * | jas_alloc3 (size_t num_arrays, size_t array_size, size_t element_size)
| Allocate array of arrays (with overflow checking).
JAS_EXPORT void * | jas_realloc2 (void *ptr, size_t num_elements, size_t element_size)
| Resize a block of allocated memory (with overflow checking).
JAS_EXPORT void | jas_set_max_mem_usage (size_t max_mem)
| Set the maximum memory usage allowed by the allocator wrapper.
JAS_EXPORT size_t | jas_get_mem_usage (void)
| Get the current memory usage from the allocator wrapper.
JAS_EXPORT void | jas_std_allocator_init (jas_std_allocator_t *allocator)
| Initialize a memory allocator that uses malloc and related functions for managing memory.
JAS_EXPORT void | jas_allocator_cleanup (jas_allocator_t *allocator)
| Clean up an allocator that is no longer needed.
JAS_EXPORT size_t | jas_get_total_mem_size (void)
| Get the total amount of memory available on the system.

## Detailed Description

Memory Allocation.

General information can be found here.

## Typedef Documentation

## ◆ jas_allocator_t

typedef struct jas_allocator_s jas_allocator_t

A memory allocator.

## Function Documentation

## ◆ jas_alloc2()

JAS_EXPORT void * jas_alloc2 | ( | size_t | num_elements,
|  | size_t | element_size )

Allocate array (with overflow checking).

## ◆ jas_alloc3()

JAS_EXPORT void * jas_alloc3 | ( | size_t | num_arrays,
|  | size_t | array_size,
|  | size_t | element_size )

Allocate array of arrays (with overflow checking).

## ◆ jas_allocator_cleanup()

JAS_EXPORT void jas_allocator_cleanup | ( | jas_allocator_t * | allocator | ) |

Clean up an allocator that is no longer needed.

This function cleans up an allocator, releasing any resources associated with the allocator. After clean up is performed, the allocator can no longer be used.

## ◆ jas_calloc()

JAS_EXPORT void * jas_calloc | ( | size_t | num_elements,
|  | size_t | element_size )

Allocate a block of memory and initialize the contents to zero.

This function has an identical behavior as calloc (from the C standard library).

## ◆ jas_free()

JAS_EXPORT void jas_free | ( | void * | ptr | ) |

Free memory.

This function has an identical behavior as free (from the C standard library).

## ◆ jas_get_mem_usage()

JAS_EXPORT size_t jas_get_mem_usage | ( | void |  | ) |

Get the current memory usage from the allocator wrapper.

This function queries the amount of memory currently in use by the allocator wrapper. This function can only be called if the use of the allocator wrapper is enabled. Calling this function if the allocator wrapper is not enabled results in undefined behavior.

## ◆ jas_get_total_mem_size()

JAS_EXPORT size_t jas_get_total_mem_size | ( | void |  | ) |

Get the total amount of memory available on the system.

This function may be called prior to the library being initialized. In fact, this function may be useful for determining a reasonable value for the memory limit setting to be used during (run-time) library configuration.

Returns
  The total amount of memory available (in bytes) is returned, if this can be determined. Otherwise, zero is returned.

## ◆ jas_malloc()

JAS_EXPORT void * jas_malloc | ( | size_t | size | ) |

Allocate memory.

This function has an identical behavior as malloc (from the C standard library), except that a zero-sized allocation returns a non-null pointer (assuming no out-of-memory error occurs).

## ◆ jas_realloc()

JAS_EXPORT void * jas_realloc | ( | void * | ptr,
|  | size_t | size )

Resize a block of allocated memory.

This function has an identical behavior as realloc (from the C standard library).

## ◆ jas_realloc2()

JAS_EXPORT void * jas_realloc2 | ( | void * | ptr,
|  | size_t | num_elements,
|  | size_t | element_size )

Resize a block of allocated memory (with overflow checking).

## ◆ jas_set_max_mem_usage()

JAS_EXPORT void jas_set_max_mem_usage | ( | size_t | max_mem | ) |

Set the maximum memory usage allowed by the allocator wrapper.

Parameters

  max_mem | The maximum amount of memory (in bytes) that the allocator can use.

This function sets the maximum amount of memory (in bytes) that the allocator wrapper is permitted to use to `max_mem`. If `max_mem` is zero, no limit is imposed on the amount of memory used by allocator. This function can only be called if the use of the allocator wrapper is enabled. Calling this function if the allocator wrapper is not enabled results in undefined behavior. The limit on the amount of memory that the allocator can use should never be set to a value less than the amount of memory currently being used by the allocator (as doing so results in undefined behavior).

## ◆ jas_std_allocator_init()

JAS_EXPORT void jas_std_allocator_init | ( | jas_std_allocator_t * | allocator | ) |

Initialize a memory allocator that uses malloc and related functions for managing memory.

Parameters

  allocator | A pointer to the storage in memory that will hold the state associated with the allocator.

The object referenced by `allocator` must have a lifetime that extends until `jas_allocator_cleanup` is called for the allocator.