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. More... | |
Functions | |
JAS_EXPORT void * | jas_malloc (size_t size) |
Allocate memory. More... | |
JAS_EXPORT void | jas_free (void *ptr) |
Free memory. More... | |
JAS_EXPORT void * | jas_realloc (void *ptr, size_t size) |
Resize a block of allocated memory. More... | |
JAS_EXPORT void * | jas_calloc (size_t num_elements, size_t element_size) |
Allocate a block of memory and initialize the contents to zero. More... | |
JAS_EXPORT void * | jas_alloc2 (size_t num_elements, size_t element_size) |
Allocate array (with overflow checking). More... | |
JAS_EXPORT void * | jas_alloc3 (size_t num_arrays, size_t array_size, size_t element_size) |
Allocate array of arrays (with overflow checking). More... | |
JAS_EXPORT void * | jas_realloc2 (void *ptr, size_t num_elements, size_t element_size) |
Resize a block of allocated memory (with overflow checking). More... | |
JAS_EXPORT void | jas_set_max_mem_usage (size_t max_mem) |
Set the maximum memory usage allowed by the allocator wrapper. More... | |
JAS_EXPORT size_t | jas_get_mem_usage (void) |
Get the current memory usage from the allocator wrapper. More... | |
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. More... | |
JAS_EXPORT void | jas_allocator_cleanup (jas_allocator_t *allocator) |
Clean up an allocator that is no longer needed. More... | |
JAS_EXPORT size_t | jas_get_total_mem_size (void) |
Get the total amount of memory available on the system. More... | |
Memory Allocation.
General information can be found here.
typedef struct jas_allocator_s jas_allocator_t |
A memory allocator.
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_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_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_EXPORT void jas_free | ( | void * | ptr | ) |
Free memory.
This function has an identical behavior as free (from the C standard library).
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_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.
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_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_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.
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_EXPORT void jas_std_allocator_init | ( | jas_std_allocator_t * | allocator | ) |
Initialize a memory allocator that uses malloc and related functions for managing memory.
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.