libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_scope_allocator.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblScopeAllocator stack-like arena sub allocator
3 * \ingroup allocators
4 * \copydoc GblScopeAllocator
5 *
6 * \author Falco Girgis
7 */
8
9#ifndef GIMBAL_SCOPE_ALLOCATOR_H
10#define GIMBAL_SCOPE_ALLOCATOR_H
11
13
14#define GBL_SELF_TYPE GblScopeAllocator
15
17
18typedef GBL_RESULT (*GblScopeAllocatorDtorFn)(void* pPtr);
19
20//! Arena-backed scope-based allocator
21typedef struct GblScopeAllocator {
22 GblArenaAllocator* pArena;
23 GblArenaAllocatorState rewindState;
24 GblLinkedListNode dtorList;
25} GblScopeAllocator;
26
27// ===== Public API =====
28GBL_EXPORT GBL_SELF_TYPE* GblScopeAllocator_create (GblArenaAllocator* pArena) GBL_NOEXCEPT;
29
30GBL_EXPORT GBL_RESULT GblScopeAllocator_construct (GBL_SELF,
31 GblArenaAllocator* pArena) GBL_NOEXCEPT;
32
33GBL_EXPORT GBL_RESULT GblScopeAllocator_destroy (GBL_SELF) GBL_NOEXCEPT;
34GBL_EXPORT GBL_RESULT GblScopeAllocator_destruct (GBL_SELF) GBL_NOEXCEPT;
35
36GBL_EXPORT void* GblScopeAllocator_alloc (GBL_SELF,
37 size_t size,
38 size_t align,
39 GblScopeAllocatorDtorFn pFnDtor) GBL_NOEXCEPT;
40
41GBL_EXPORT GBL_RESULT GblScopeAllocator_pushDtor (GBL_SELF,
42 GblScopeAllocatorDtorFn pFnDtor,
43 void* pData) GBL_NOEXCEPT;
44
45GBL_EXPORT size_t GblScopeAllocator_dtorCount (GBL_CSELF) GBL_NOEXCEPT;
46
47// ===== Macro Overrides =====
48#define GblScopeAllocator_alloc(...) GblScopeAllocator_allocDefault_(__VA_ARGS__)
49#define GblScopeAllocator_pushDtor(...) GblScopeAllocator_pushDtorDefault_(__VA_ARGS__)
50
51// ===== Implementation =====
52#define GblScopeAllocator_allocDefault_(...)
54#define GblScopeAllocator_allocDefault__(self, size, align, dtor, ...)
55 (GblScopeAllocator_alloc)(self, size, align, dtor)
56
57#define GblScopeAllocator_pushDtorDefault_(...)
59#define GblScopeAllocator_pushDtorDefault__(self, dtor, data, ...)
60 (GblScopeAllocator_pushDtor)(self, dtor, data)
61
63
64#undef GBL_SELF_TYPE
65
66#endif // GIMBAL_SCOPE_ALLOCATOR_H
#define GBL_NULL
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_EXPORT
#define GBL_SELF_TYPE
Definition gimbal_md5.h:22
#define GblScopeAllocator_allocDefault__(self, size, align, dtor,...)
#define GblScopeAllocator_pushDtorDefault__(self, dtor, data,...)
#define GblScopeAllocator_pushDtor(...)
#define GblScopeAllocator_pushDtorDefault_(...)
#define GblScopeAllocator_allocDefault_(...)
#define GblScopeAllocator_alloc(...)
Arena-backed scope-based allocator.