Barracuda Application Server C/C++ Reference
NO
AllocatorIntf.h
1/*
2 * ____ _________ __ _
3 * / __ \___ ____ _/ /_ __(_)___ ___ ___ / / ____ ____ _(_)____
4 * / /_/ / _ \/ __ `/ / / / / / __ `__ \/ _ \/ / / __ \/ __ `/ / ___/
5 * / _, _/ __/ /_/ / / / / / / / / / / / __/ /___/ /_/ / /_/ / / /__
6 * /_/ |_|\___/\__,_/_/ /_/ /_/_/ /_/ /_/\___/_____/\____/\__, /_/\___/
7 * /____/
8 *
9 * Barracuda Application Server
10 *
11 ****************************************************************************
12 * HEADER
13 *
14 * $Id: AllocatorIntf.h 4914 2021-12-01 18:24:30Z 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
38#ifndef __AllocatorIntf_h
39#define __AllocatorIntf_h
40
41#include <TargConfig.h>
42#include <stddef.h>
43
44#ifndef BA_API
45#define BA_API
46#endif
47
48
49struct AllocatorIntf;
50
56typedef void* (*AllocatorIntf_Malloc)(struct AllocatorIntf* o, size_t* size);
57
63typedef void* (*AllocatorIntf_Realloc)(
64 struct AllocatorIntf* o, void* memblock, size_t* size);
65
69typedef void (*AllocatorIntf_Free)(struct AllocatorIntf* o, void* memblock);
70
82typedef struct AllocatorIntf
83{
84#ifdef __cplusplus
85 AllocatorIntf() {}
94 AllocatorIntf(AllocatorIntf_Malloc malloc,
95 AllocatorIntf_Realloc realloc,
96 AllocatorIntf_Free free);
97
102 static AllocatorIntf* getDefault(void);
103
109 void* malloc(size_t* size);
110 void* malloc(size_t size) { return malloc(&size); }
111
117 void* realloc(void* p, size_t* size);
118 void* realloc(void* p, size_t size) { return realloc(p, &size); }
119
122 void free(void* p);
123#endif
124 AllocatorIntf_Malloc mallocCB;
125 AllocatorIntf_Realloc reallocCB; /* optional */
126 AllocatorIntf_Free freeCB;
128
129#define AllocatorIntf_constructor(o, m, r, f) do { \
130 (o)->mallocCB=m; \
131 (o)->reallocCB=r; \
132 (o)->freeCB=f; \
133} while(0)
134
135#define AllocatorIntf_malloc(o, size) (o)->mallocCB(o, size)
136#define AllocatorIntf_realloc(o, memblock, size) \
137 ((o)->reallocCB ? (o)->reallocCB(o,memblock,size) : 0)
138#define AllocatorIntf_free(o, memblock) (o)->freeCB(o,memblock)
139
140#ifdef __cplusplus
141extern "C" {
142#endif
143BA_API AllocatorIntf* AllocatorIntf_getDefault(void);
144
148BA_API char* baStrdup2(struct AllocatorIntf* a, const char* str);
149
150#ifdef __cplusplus
151}
152inline AllocatorIntf::AllocatorIntf(AllocatorIntf_Malloc malloc,
153 AllocatorIntf_Realloc realloc,
154 AllocatorIntf_Free free) {
155 AllocatorIntf_constructor(this, malloc,realloc,free); }
157 return AllocatorIntf_getDefault(); }
158inline void* AllocatorIntf::malloc(size_t* size) {
159 return AllocatorIntf_malloc(this, size); }
160inline void* AllocatorIntf::realloc(void* memblock, size_t* size) {
161 return AllocatorIntf_realloc(this, memblock, size); }
162inline void AllocatorIntf::free(void* memblock) {
163 AllocatorIntf_free(this, memblock); }
164#endif
165
166#endif
Memory allocation and deallocation Interface class.
Definition: AllocatorIntf.h:83
void * realloc(void *p, size_t *size)
Returns pointer to newly-allocated space for an object of size "size", initialized,...
Definition: AllocatorIntf.h:160
void * malloc(size_t *size)
Returns pointer to uninitialized newly-allocated space for an object of size "size",...
Definition: AllocatorIntf.h:158
void free(void *p)
Deallocates space to which it points.
Definition: AllocatorIntf.h:162
static AllocatorIntf * getDefault(void)
Returns a pointer to a predefined AllocatorIntf class.
Definition: AllocatorIntf.h:156