ShinyAllocator  1.0
ShinyAllocator is a library of a block memory allocator for real-time high-integrity embedded systems.
shinyAllocator.h
Go to the documentation of this file.
1 /***
2  * @brief header file for shinyAllocator library
3  * @filename shinyAllocator.h
4  * @author Ehsan Shaghaei <ehsan2754@gmail.com>
5  * @date Dec 27, 2022
6  * @version 1.0.0
7  *
8  * @copyright 2022 GNU GENERAL PUBLIC LICENSE
9  *
10  */
11 #ifndef __shinyAllocator_h
12 #define __shinyAllocator_h
13 
14 #include <stddef.h>
15 #include <stdint.h>
16 #include <stdbool.h>
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
26 #define SHINYALLOCATOR_VERSION_MAJOR 1
27 #define SHINYALLOCATOR_VERSION_MINOR 0
28 
33 #define SHINYALLOCATOR_ALIGNMENT (sizeof(void *) * 4U)
34 
40  typedef int_fast8_t SHINY_STATUS;
53  typedef struct
54  {
55  size_t capacity;
56  size_t allocated;
57  size_t peakAllocated;
61 
65  size_t sizeof_shinyAllocatorInstance(void);
66 
71 
77 
86  shinyAllocatorInstance *shinyInit(void *const base, const size_t size);
87 
94  void *shinyAllocate(shinyAllocatorInstance *const handle, const size_t amount);
95 
101  void shinyFree(shinyAllocatorInstance *const handle, void *const pointer);
102 
109 
116  shinyAllocatorThreadSafeInstance *shinyInitThreadSafe(void *const base, const size_t size);
117 
124  void *shinyAllocateThreadSafe(shinyAllocatorThreadSafeInstance *const threadSafeHandle, const size_t amount);
125 
131  SHINY_STATUS shinyFreeThreadSafe(shinyAllocatorThreadSafeInstance *const threadSafeHandle, void *const pointer);
132 
139 #ifdef __cplusplus
140 }
141 #endif
142 #endif // __shinyAllocator_h
void shinyFree(shinyAllocatorInstance *const handle, void *const pointer)
Frees the memory allocated to the given the pool handle.
Definition: shinyAllocator.c:515
int_fast8_t SHINY_STATUS
Definition: shinyAllocator.h:40
shinyAllocatorThreadSafeInstance * shinyInitThreadSafe(void *const base, const size_t size)
Initializes a thread-safe shinyAllocator instance.
Definition: shinyAllocator.c:592
void * shinyAllocate(shinyAllocatorInstance *const handle, const size_t amount)
Allocated the requested memory to the given the pool handle, returns NULL if it fails.
Definition: shinyAllocator.c:439
shinyAllocatorDiagnostics shinyGetDiagnostics(shinyAllocatorInstance *handle)
Definition: shinyAllocator.c:377
shinyAllocatorDiagnostics shinyGetDiagnosticsThreadSafe(shinyAllocatorThreadSafeInstance *const threadSafeHandle)
Thread-safe wrapper for shinyGetDiagnostics().
Definition: shinyAllocator.c:581
size_t sizeof_shinyAllocatorThreadSafeInstance(void)
Definition: shinyAllocator.c:372
shinyAllocatorInstance * shinyInit(void *const base, const size_t size)
Initializes the shinyAllocator for the given base pointer and size.
Definition: shinyAllocator.c:392
SHINY_STATUS shinyDeinitThreadSafe(shinyAllocatorThreadSafeInstance *const threadSafeHandle)
Deinitializes a thread-safe shinyAllocator instance.
Definition: shinyAllocator.c:657
size_t sizeof_shinyAllocatorInstance(void)
Definition: shinyAllocator.c:368
void * shinyAllocateThreadSafe(shinyAllocatorThreadSafeInstance *const threadSafeHandle, const size_t amount)
Allocates memory from a thread-safe shinyAllocator instance.
Definition: shinyAllocator.c:630
SHINY_STATUS shinyFreeThreadSafe(shinyAllocatorThreadSafeInstance *const threadSafeHandle, void *const pointer)
Frees memory allocated by a thread-safe shinyAllocator instance.
Definition: shinyAllocator.c:645
shinyAllocator instance
Definition: shinyAllocator.h:54
size_t peakRequestSize
Definition: shinyAllocator.h:58
size_t capacity
Definition: shinyAllocator.h:55
size_t outOfMemeoryCount
Definition: shinyAllocator.h:59
size_t peakAllocated
Definition: shinyAllocator.h:57
size_t allocated
Definition: shinyAllocator.h:56
the allocator which stores the information about the pool structure
Definition: shinyAllocator.c:219
Initializes the allocator.
Definition: shinyAllocator.c:232
shinyAllocatorInstance * handle
Definition: shinyAllocator.c:234