#include <TargConfig.h>
#include <stddef.h>
Go to the source code of this file.
|
| #define | AllocatorIntf_constructor(o, m, r, f) |
| | Install allocator callbacks without allocating any memory. More...
|
| |
| #define | AllocatorIntf_malloc(o, size) (o)->mallocCB(o, size) |
| | Dispatch an allocation request. More...
|
| |
| #define | AllocatorIntf_realloc(o, memblock, size) ((o)->reallocCB ? (o)->reallocCB(o,memblock,size) : 0) |
| | Dispatch a resize request. More...
|
| |
| #define | AllocatorIntf_free(o, memblock) (o)->freeCB(o,memblock) |
| | Dispatch a deallocation request. More...
|
| |
◆ AllocatorIntf_constructor
| #define AllocatorIntf_constructor |
( |
|
o, |
|
|
|
m, |
|
|
|
r, |
|
|
|
f |
|
) |
| |
Value: do { \
(o)->mallocCB=m; \
(o)->reallocCB=r; \
(o)->freeCB=f; \
} while(0)
Install allocator callbacks without allocating any memory.
- Parameters
-
| [out] | o | Caller-owned allocator object. |
| [in] | m | Required allocation callback. |
| [in] | r | Optional resize callback; NULL disables resizing. |
| [in] | f | Required deallocation callback. |
◆ AllocatorIntf_free
| #define AllocatorIntf_free |
( |
|
o, |
|
|
|
memblock |
|
) |
| (o)->freeCB(o,memblock) |
Dispatch a deallocation request.
- Parameters
-
| [in,out] | o | Initialized allocator. |
| [in] | memblock | Block to release; see AllocatorIntf_Free. |
◆ AllocatorIntf_malloc
| #define AllocatorIntf_malloc |
( |
|
o, |
|
|
|
size |
|
) |
| (o)->mallocCB(o, size) |
Dispatch an allocation request.
- Parameters
-
| [in,out] | o | Initialized allocator. |
| [in,out] | size | Requested byte count; see AllocatorIntf_Malloc. |
- Returns
- New storage or NULL on failure.
◆ AllocatorIntf_realloc
| #define AllocatorIntf_realloc |
( |
|
o, |
|
|
|
memblock, |
|
|
|
size |
|
) |
| ((o)->reallocCB ? (o)->reallocCB(o,memblock,size) : 0) |
Dispatch a resize request.
- Parameters
-
| [in,out] | o | Initialized allocator. |
| [in] | memblock | Existing block or NULL; see AllocatorIntf_Realloc. |
| [in,out] | size | Requested byte count; see AllocatorIntf_Realloc. |
- Returns
- Replacement block or NULL. An absent callback returns NULL and leaves the original block and size unchanged.
◆ AllocatorIntf
Memory allocation and deallocation Interface class.
This abstract interface class is used by some of the Barracuda classes when allocating memory. The reason for using an interface class and not directly calling the global functions baMalloc(), baRealloc() and baFree() is to provide a finer control of allocated memory. For example, an implementation of the AllocatorIntf can work with blocks of memory allocated from static memory. Implementing realloc is optional and can be set to NULL if not implemented.
◆ AllocatorIntf_Free
| typedef void(* AllocatorIntf_Free) (struct AllocatorIntf *o, void *memblock) |
Release a block.
- Parameters
-
| [in,out] | o | Allocator instance supplied to the callback. |
| [in] | memblock | Live block obtained from this allocator. NULL handling depends on the implementation; FixedSizeAllocator requires a non-NULL block. The pointer must not be used after the callback returns. |
◆ AllocatorIntf_Malloc
| typedef void *(* AllocatorIntf_Malloc) (struct AllocatorIntf *o, size_t *size) |
Allocate a block using an allocator implementation.
- Parameters
-
| [in,out] | o | Allocator instance supplied to the callback. |
| [in,out] | size | Required pointer to the requested byte count. On success the implementation may increase it to the actual allocation size. Its value on failure, and the handling of a zero request, depend on the implementation. |
- Returns
- Uninitialized storage of at least the requested size, or NULL on failure. Release successful allocations with the same allocator's free callback. The allocator object must outlive its allocated blocks.
◆ AllocatorIntf_Realloc
| typedef void *(* AllocatorIntf_Realloc) (struct AllocatorIntf *o, void *memblock, size_t *size) |
Resize a block using the same allocator that allocated it.
- Parameters
-
| [in,out] | o | Allocator instance supplied to the callback. |
| [in] | memblock | Existing allocation, or NULL to request a new block. |
| [in,out] | size | Required requested byte count. On success it may be increased to the actual size. Use a positive size for portable behavior; zero-size behavior depends on the allocator implementation. |
- Returns
- Replacement block preserving the smaller of the old and new byte counts, or NULL on failure. For a positive request, failure leaves memblock owned by the caller; success invalidates the old pointer. New bytes are not initialized. This callback is optional in AllocatorIntf.
◆ AllocatorIntf_getDefault()
- Returns
- Borrowed process-lifetime allocator backed by baMalloc, baRealloc and baFree. Do not free it or change its callbacks.
◆ baStrdup2()
| BA_API char * baStrdup2 |
( |
struct AllocatorIntf * |
a, |
|
|
const char * |
str |
|
) |
| |
Allocate a NUL-terminated copy of a string.
- Parameters
-
| [in,out] | a | Required initialized allocator, used only when str is non-NULL. |
| [in] | str | NUL-terminated source string, or NULL. The source is not modified. |
- Returns
- Independent copy, or NULL when str is NULL or allocation fails. Release a successful result through a. The allocation includes the NUL byte.