libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_iallocator.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblIAllocator abstract allocator interface
3 * \ingroup interfaces
4 * \todo
5 * - make specific allocators implement me
6 *
7 * \author 2023 Falco Girgis
8 * \copyright MIT License
9 */
10
11#ifndef GIMBAL_IALLOCATOR_H
12#define GIMBAL_IALLOCATOR_H
13
15#include "../../core/gimbal_ctx.h"
16
17/*! \name Type System
18 * \brief Type UUID and cast operators
19 * @{
20 */
21#define GBL_IALLOCATOR_TYPE (GBL_TYPEID(GblIAllocator)) //!< Type UUID for GblIAllocator
22#define GBL_IALLOCATOR(self) (GBL_CAST(GblIAllocator, self)) //!< Casts a GblInstance to GblIAllocator
23#define GBL_IALLOCATOR_CLASS(klass) (GBL_CLASS_CAST(GblIAllocator, klass)) //!< Casts a GblClass to GblIAllocatorClass
24#define GBL_IALLOCATOR_GET_CLASS(self) (GBL_CLASSOF(GblIAllocator, self)) //!< Gets a GblIAllocatorClass from a GblInstance
25//! @}
26
27#define GBL_SELF_TYPE GblIAllocator
28
30
31/*! \struct GblIAllocatorClass
32 * \extends GblInterface
33 * \brief GblClass VTable structure for GblIAllocator
34 *
35 * GblIAllocatorClass provides polymorphic methods for
36 * basic memory management operations: alloc, realloc, free.
37 *
38 * \note
39 * All operations are required to honor the requested alignment.
40 */
42 //! Virtual method invoked when an allocation is requested
43 GBL_RESULT (*pFnAlloc) (GBL_SELF, const GblStackFrame* pFrame, size_t size, size_t align, const char* pDbgStr, void** ppData);
44 //! Virtual method invoked when a reallocation is requested
45 GBL_RESULT (*pFnRealloc) (GBL_SELF, const GblStackFrame* pFrame, void* pData, size_t newSize, size_t newAlign, void** ppNewData);
46 //! Virtual method invoked when a free is requested
47 GBL_RESULT (*pFnFree) (GBL_SELF, const GblStackFrame* pFrame, void* pData);
48 //! Virtual method for retrieving the upstream parent fallback allocator
49 GBL_RESULT (*pFnParent) (GBL_CSELF, GblIAllocator** ppParent);
51
52//! Returns the GblType UUID associated with the GblIAllocator type
54
55/*! \name Memory Management
56 * \brief Memory allocation, reallocation, and freeing entry points
57 * @{
58 */
59GBL_EXPORT GBL_RESULT GblIAllocator_alloc (GBL_SELF,
60 const GblStackFrame* pFrame,
61 size_t size,
62 size_t alignment,
63 const char* pDebugString,
64 void** ppData) GBL_NOEXCEPT;
65
66GBL_EXPORT GBL_RESULT GblIAllocator_realloc (GBL_SELF,
67 const GblStackFrame* pFrame,
68 void* pData,
69 size_t newSize,
70 size_t newAlign,
71 void** ppNewData) GBL_NOEXCEPT;
72
73GBL_EXPORT GBL_RESULT GblIAllocator_free (GBL_SELF,
74 const GblStackFrame* pFrame,
75 void* pData) GBL_NOEXCEPT;
76//! @}
77
78GBL_EXPORT GblIAllocator* GblIAllocator_parent(GBL_CSELF) GBL_NOEXCEPT;
79
81
82#undef GBL_SELF_TYPE
83
84#endif // GIMBAL_IALLOCATOR_H
#define GBL_CLASS_CAST(cType, klass)
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_TYPEID(instanceStruct)
#define GBL_INTERFACE_END
#define GBL_INTERFACE_DERIVE(...)
#define GBL_EXPORT
GblType GblIAllocator_type(void)
Returns the GblType UUID associated with the GblIAllocator type.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51