Barracuda Application Server C/C++ Reference
Native APIs, integration guides, and platform interfaces
AllocatorIntf.h
Go to the documentation of this file.
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Application Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: AllocatorIntf.h 5978 2026-09-11 16:13:48Z wini $
15 *
16 * COPYRIGHT: Real Time Logic LLC, 2014
17 *
18 * This software is copyrighted by and is the sole property of Real
19 * Time Logic LLC. All rights, title, ownership, or other interests in
20 * the software remain the property of Real Time Logic LLC. This
21 * software may only be used in accordance with the terms and
22 * conditions stipulated in the corresponding license agreement under
23 * which the software has been supplied. Any unauthorized use,
24 * duplication, transmission, distribution, or disclosure of this
25 * software is expressly forbidden.
26 *
27 * This Copyright notice may not be removed or modified without prior
28 * written consent of Real Time Logic LLC.
29 *
30 * Real Time Logic LLC. reserves the right to modify this software
31 * without notice.
32 *
33 * http://realtimelogic.com
34 ****************************************************************************
35 *
36 */
37
40#ifndef __AllocatorIntf_h
41#define __AllocatorIntf_h
42
43#include <TargConfig.h>
44#include <stddef.h>
45
46#ifndef BA_API
47#define BA_API
48#endif
49
50
51struct AllocatorIntf;
52
62typedef void* (*AllocatorIntf_Malloc)(struct AllocatorIntf* o, size_t* size);
63
75typedef void* (*AllocatorIntf_Realloc)(
76 struct AllocatorIntf* o, void* memblock, size_t* size);
77
84typedef void (*AllocatorIntf_Free)(struct AllocatorIntf* o, void* memblock);
85
97typedef struct AllocatorIntf
98{
99#ifdef __cplusplus
113
117 static AllocatorIntf* getDefault(void);
118
122 void* malloc(size_t* size);
126 void* malloc(size_t size) { return malloc(&size); }
127
133 void* realloc(void* p, size_t* size);
138 void* realloc(void* p, size_t size) { return realloc(p, &size); }
139
143 void free(void* p);
144#endif
145 AllocatorIntf_Malloc mallocCB;
146 AllocatorIntf_Realloc reallocCB; /* optional */
147 AllocatorIntf_Free freeCB;
149
155#define AllocatorIntf_constructor(o, m, r, f) do { \
156 (o)->mallocCB=m; \
157 (o)->reallocCB=r; \
158 (o)->freeCB=f; \
159} while(0)
160
165#define AllocatorIntf_malloc(o, size) (o)->mallocCB(o, size)
172#define AllocatorIntf_realloc(o, memblock, size) \
173 ((o)->reallocCB ? (o)->reallocCB(o,memblock,size) : 0)
177#define AllocatorIntf_free(o, memblock) (o)->freeCB(o,memblock)
178
179#ifdef __cplusplus
180extern "C" {
181#endif
185
192BA_API char* baStrdup2(struct AllocatorIntf* a, const char* str);
193
194#ifdef __cplusplus
195}
197 AllocatorIntf_Realloc realloc,
198 AllocatorIntf_Free free) {
201 return AllocatorIntf_getDefault(); }
202inline void* AllocatorIntf::malloc(size_t* size) {
203 return AllocatorIntf_malloc(this, size); }
204inline void* AllocatorIntf::realloc(void* memblock, size_t* size) {
205 return AllocatorIntf_realloc(this, memblock, size); }
206inline void AllocatorIntf::free(void* memblock) {
207 AllocatorIntf_free(this, memblock); }
208#endif
209
210#endif
struct AllocatorIntf AllocatorIntf
Memory allocation and deallocation Interface class.
void *(* AllocatorIntf_Realloc)(struct AllocatorIntf *o, void *memblock, size_t *size)
Resize a block using the same allocator that allocated it.
Definition: AllocatorIntf.h:75
void *(* AllocatorIntf_Malloc)(struct AllocatorIntf *o, size_t *size)
Allocate a block using an allocator implementation.
Definition: AllocatorIntf.h:62
BA_API AllocatorIntf * AllocatorIntf_getDefault(void)
#define AllocatorIntf_realloc(o, memblock, size)
Dispatch a resize request.
Definition: AllocatorIntf.h:172
#define AllocatorIntf_malloc(o, size)
Dispatch an allocation request.
Definition: AllocatorIntf.h:165
void(* AllocatorIntf_Free)(struct AllocatorIntf *o, void *memblock)
Release a block.
Definition: AllocatorIntf.h:84
#define AllocatorIntf_constructor(o, m, r, f)
Install allocator callbacks without allocating any memory.
Definition: AllocatorIntf.h:155
BA_API char * baStrdup2(struct AllocatorIntf *a, const char *str)
Allocate a NUL-terminated copy of a string.
#define AllocatorIntf_free(o, memblock)
Dispatch a deallocation request.
Definition: AllocatorIntf.h:177
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:98
void * realloc(void *p, size_t *size)
Resize an allocation.
Definition: AllocatorIntf.h:204
void * malloc(size_t *size)
Allocate uninitialized storage.
Definition: AllocatorIntf.h:202
AllocatorIntf()
Leave callbacks uninitialized; initialize them before use.
Definition: AllocatorIntf.h:101
void free(void *p)
Release an allocation.
Definition: AllocatorIntf.h:206
void * realloc(void *p, size_t size)
Resize without returning the adjusted allocation size.
Definition: AllocatorIntf.h:138
static AllocatorIntf * getDefault(void)
Obtain the shared allocator backed by baMalloc, baRealloc and baFree.
Definition: AllocatorIntf.h:200
void * malloc(size_t size)
Allocate without returning the adjusted allocation size.
Definition: AllocatorIntf.h:126