![]() |
ucx
UAP Common Extensions
|
Interface for custom allocators. More...
#include "common.h"Go to the source code of this file.
Data Structures | |
| struct | cx_allocator_class |
| The class definition for an allocator. More... | |
| struct | cx_allocator_s |
| Structure holding the data for an allocator. More... | |
Macros | |
| #define | cx_reallocate(mem, n) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| #define | cx_reallocatearray(mem, nmemb, size) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| #define | cx_zalloc(n) |
| Allocates memory and sets every byte to zero. | |
| #define | cxReallocate(allocator, mem, n) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| #define | cxReallocateArray(allocator, mem, nmemb, size) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| #define | cxMallocDefault(...) |
| Convenience macro that invokes cxMalloc() with the cxDefaultAllocator. | |
| #define | cxZallocDefault(...) |
| Convenience macro that invokes cxZalloc() with the cxDefaultAllocator. | |
| #define | cxCallocDefault(...) |
| Convenience macro that invokes cxCalloc() with the cxDefaultAllocator. | |
| #define | cxReallocDefault(...) |
| Convenience macro that invokes cxRealloc() with the cxDefaultAllocator. | |
| #define | cxReallocateDefault(...) |
| Convenience macro that invokes cxReallocate() with the cxDefaultAllocator. | |
| #define | cxReallocateArrayDefault(...) |
| Convenience macro that invokes cxReallocateArray() with the cxDefaultAllocator. | |
| #define | cxReallocArrayDefault(...) |
| Convenience macro that invokes cxReallocArray() with the cxDefaultAllocator. | |
| #define | cxFreeDefault(...) |
| Convenience macro that invokes cxFree() with the cxDefaultAllocator. | |
Typedefs | |
| typedef struct cx_allocator_s | CxAllocator |
| High-Level type alias for the allocator type. | |
| typedef void(* | cx_destructor_func) (void *memory) |
| Function pointer type for destructor functions. | |
| typedef void(* | cx_destructor_func2) (void *data, void *memory) |
| Function pointer type for destructor functions. | |
| typedef void * | cx_clone_func(void *target, const void *source, const CxAllocator *allocator, void *data) |
| Function pointer type for clone functions. | |
Functions | |
| int | cx_reallocate_ (void **mem, size_t n) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| int | cx_reallocatearray_ (void **mem, size_t nmemb, size_t size) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| void | cxFree (const CxAllocator *allocator, void *mem) |
| Free a block allocated by this allocator. | |
| void * | cxMalloc (const CxAllocator *allocator, size_t n) |
Allocate n bytes of memory. | |
| void * | cxRealloc (const CxAllocator *allocator, void *mem, size_t n) |
Reallocate the previously allocated block in mem, making the new block n bytes long. | |
| void * | cxReallocArray (const CxAllocator *allocator, void *mem, size_t nmemb, size_t size) |
Reallocate the previously allocated block in mem, making the new block n bytes long. | |
| int | cxReallocate_ (const CxAllocator *allocator, void **mem, size_t n) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| int | cxReallocateArray_ (const CxAllocator *allocator, void **mem, size_t nmemb, size_t size) |
| Reallocate a previously allocated block and changes the pointer in-place, if necessary. | |
| void * | cxCalloc (const CxAllocator *allocator, size_t nmemb, size_t size) |
Allocate nmemb elements of n bytes each, all initialized to zero. | |
| void * | cxZalloc (const CxAllocator *allocator, size_t n) |
Allocate n bytes of memory and sets every byte to zero. | |
Variables | |
| const CxAllocator *const | cxStdlibAllocator |
| A pre-defined allocator using standard library malloc() etc. | |
| const CxAllocator * | cxDefaultAllocator |
| The default allocator that is used by UCX. | |
Interface for custom allocators.
| #define cx_reallocate | ( | mem, | |
| n ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
errno will be set by realloc() on failure.| mem | (void**) pointer to the pointer to allocated block |
| n | (size_t) the new size in bytes |
| zero | success |
| non-zero | failure |
| #define cx_reallocatearray | ( | mem, | |
| nmemb, | |||
| size ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
The size is calculated by multiplying nemb and size.
errno will be set by realloc() on failure or when the multiplication of nmemb and size overflows.| mem | (void**) pointer to the pointer to allocated block |
| nmemb | (size_t) the number of elements |
| size | (size_t) the size of each element |
| zero | success |
| non-zero | failure |
| #define cx_zalloc | ( | n | ) |
Allocates memory and sets every byte to zero.
| n | (size_t) the number of bytes |
void*) a pointer to the allocated memory | #define cxCallocDefault | ( | ... | ) |
Convenience macro that invokes cxCalloc() with the cxDefaultAllocator.
| #define cxFreeDefault | ( | ... | ) |
Convenience macro that invokes cxFree() with the cxDefaultAllocator.
| #define cxMallocDefault | ( | ... | ) |
Convenience macro that invokes cxMalloc() with the cxDefaultAllocator.
| #define cxReallocArrayDefault | ( | ... | ) |
Convenience macro that invokes cxReallocArray() with the cxDefaultAllocator.
| #define cxReallocate | ( | allocator, | |
| mem, | |||
| n ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
This function acts like cxRealloc() using the pointer pointed to by mem.
errno will be set if the underlying realloc function does so.| allocator | (CxAllocator*) the allocator |
| mem | (void**) pointer to the pointer to allocated block |
| n | (size_t) the new size in bytes |
| zero | success |
| non-zero | failure |
| #define cxReallocateArray | ( | allocator, | |
| mem, | |||
| nmemb, | |||
| size ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
This function acts like cxReallocArray() using the pointer pointed to by mem.
errno will be set, if the underlying realloc function does so or the multiplication of nmemb and size overflows.| allocator | (CxAllocator*) the allocator |
| mem | (void**) pointer to the pointer to allocated block |
| nmemb | (size_t) the number of elements |
| size | (size_t) the size of each element |
| zero | success |
| non-zero | failure |
| #define cxReallocateArrayDefault | ( | ... | ) |
Convenience macro that invokes cxReallocateArray() with the cxDefaultAllocator.
| #define cxReallocateDefault | ( | ... | ) |
Convenience macro that invokes cxReallocate() with the cxDefaultAllocator.
| #define cxReallocDefault | ( | ... | ) |
Convenience macro that invokes cxRealloc() with the cxDefaultAllocator.
| #define cxZallocDefault | ( | ... | ) |
Convenience macro that invokes cxZalloc() with the cxDefaultAllocator.
| typedef void * cx_clone_func(void *target, const void *source, const CxAllocator *allocator, void *data) |
Function pointer type for clone functions.
A clone function is supposed to create a deep copy of the memory pointed to by the source pointer. If the target pointer is non-null, the clone function is supposed to store the copy into that memory region. Otherwise, the clone function shall use the specified allocator to create a new object.
The return value of a clone function is always a pointer to the target memory region, or NULL if any allocation failed. A clone function SHOULD NOT fail for any other reason than an allocation failure.
| target | the target memory or NULL, if memory shall be allocated |
| source | the source memory |
| allocator | the allocator that shall be used |
| data | optional additional data |
target, a pointer to the allocated memory, or NULL, if any error occurred | typedef void(* cx_destructor_func) (void *memory) |
Function pointer type for destructor functions.
A destructor function deallocates possible contents and MAY free the memory pointed to by memory. Read the documentation of the respective function pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in that particular implementation.
| memory | a pointer to the object to destruct |
| typedef void(* cx_destructor_func2) (void *data, void *memory) |
Function pointer type for destructor functions.
A destructor function deallocates possible contents and MAY free the memory pointed to by memory. Read the documentation of the respective function pointer to learn if a destructor SHALL, MAY, or MUST NOT free the memory in that particular implementation.
| data | an optional pointer to custom data |
| memory | a pointer to the object to destruct |
| int cx_reallocate_ | ( | void ** | mem, |
| size_t | n ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
errno will be set by realloc() on failure.| mem | pointer to the pointer to allocated block |
| n | the new size in bytes |
| zero | success |
| non-zero | failure |
| int cx_reallocatearray_ | ( | void ** | mem, |
| size_t | nmemb, | ||
| size_t | size ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
The size is calculated by multiplying nemb and size.
errno will be set by realloc() on failure or when the multiplication of nmemb and size overflows.| mem | pointer to the pointer to allocated block |
| nmemb | the number of elements |
| size | the size of each element |
| zero | success |
| non-zero | failure |
| void * cxCalloc | ( | const CxAllocator * | allocator, |
| size_t | nmemb, | ||
| size_t | size ) |
Allocate nmemb elements of n bytes each, all initialized to zero.
| allocator | the allocator |
| nmemb | the number of elements |
| size | the size of each element in bytes |
| void cxFree | ( | const CxAllocator * | allocator, |
| void * | mem ) |
Free a block allocated by this allocator.
| allocator | the allocator |
| mem | a pointer to the block to free |
| void * cxMalloc | ( | const CxAllocator * | allocator, |
| size_t | n ) |
Allocate n bytes of memory.
| allocator | the allocator |
| n | the number of bytes |
| void * cxRealloc | ( | const CxAllocator * | allocator, |
| void * | mem, | ||
| size_t | n ) |
Reallocate the previously allocated block in mem, making the new block n bytes long.
This function may return the same pointer passed to it if moving the memory was not necessary.
| allocator | the allocator |
| mem | pointer to the previously allocated block |
| n | the new size in bytes |
| void * cxReallocArray | ( | const CxAllocator * | allocator, |
| void * | mem, | ||
| size_t | nmemb, | ||
| size_t | size ) |
Reallocate the previously allocated block in mem, making the new block n bytes long.
This function may return the same pointer passed to it if moving the memory was not necessary.
The size is calculated by multiplying nemb and size. If that multiplication overflows, this function returns NULL, and errno will be set.
| allocator | the allocator |
| mem | pointer to the previously allocated block |
| nmemb | the number of elements |
| size | the size of each element |
| int cxReallocate_ | ( | const CxAllocator * | allocator, |
| void ** | mem, | ||
| size_t | n ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
This function acts like cxRealloc() using the pointer pointed to by mem.
errno will be set if the underlying realloc function does so.| allocator | the allocator |
| mem | pointer to the pointer to allocated block |
| n | the new size in bytes |
| zero | success |
| non-zero | failure |
| int cxReallocateArray_ | ( | const CxAllocator * | allocator, |
| void ** | mem, | ||
| size_t | nmemb, | ||
| size_t | size ) |
Reallocate a previously allocated block and changes the pointer in-place, if necessary.
This function acts like cxReallocArray() using the pointer pointed to by mem.
errno will be set, if the underlying realloc function does so or the multiplication of nmemb and size overflows.| allocator | the allocator |
| mem | pointer to the pointer to allocated block |
| nmemb | the number of elements |
| size | the size of each element |
| zero | success |
| non-zero | on failure |
| void * cxZalloc | ( | const CxAllocator * | allocator, |
| size_t | n ) |
Allocate n bytes of memory and sets every byte to zero.
| allocator | the allocator |
| n | the number of bytes |
|
extern |
The default allocator that is used by UCX.
Initialized with cxStdlibAllocator, but you may change it.