ShinyAllocator  1.0
ShinyAllocator is a library of a block memory allocator for real-time high-integrity embedded systems.
Classes | Macros | Typedefs | Functions
shinyAllocator.h File Reference
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
Include dependency graph for shinyAllocator.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  shinyAllocatorDiagnostics
 shinyAllocator instance More...
 

Macros

#define SHINYALLOCATOR_VERSION_MAJOR   1
 static version number More...
 
#define SHINYALLOCATOR_VERSION_MINOR   0
 
#define SHINYALLOCATOR_ALIGNMENT   (sizeof(void *) * 4U)
 Memory alignment based on platform pointer (8/16/32) More...
 

Typedefs

typedef struct shinyAllocatorInstance shinyAllocatorInstance
 encapsulation of the structure instance More...
 
typedef struct shinyAllocatorThreadSafeInstance shinyAllocatorThreadSafeInstance
 
typedef int_fast8_t SHINY_STATUS
 

Functions

size_t sizeof_shinyAllocatorInstance (void)
 
size_t sizeof_shinyAllocatorThreadSafeInstance (void)
 
shinyAllocatorDiagnostics shinyGetDiagnostics (shinyAllocatorInstance *handle)
 
shinyAllocatorInstanceshinyInit (void *const base, const size_t size)
 Initializes the shinyAllocator for the given base pointer and size. More...
 
void * shinyAllocate (shinyAllocatorInstance *const handle, const size_t amount)
 Allocated the requested memory to the given the pool handle, returns NULL if it fails. More...
 
void shinyFree (shinyAllocatorInstance *const handle, void *const pointer)
 Frees the memory allocated to the given the pool handle. More...
 
shinyAllocatorDiagnostics shinyGetDiagnosticsThreadSafe (shinyAllocatorThreadSafeInstance *const threadSafeHandle)
 Thread-safe wrapper for shinyGetDiagnostics(). More...
 
shinyAllocatorThreadSafeInstanceshinyInitThreadSafe (void *const base, const size_t size)
 Initializes a thread-safe shinyAllocator instance. More...
 
void * shinyAllocateThreadSafe (shinyAllocatorThreadSafeInstance *const threadSafeHandle, const size_t amount)
 Allocates memory from a thread-safe shinyAllocator instance. More...
 
SHINY_STATUS shinyFreeThreadSafe (shinyAllocatorThreadSafeInstance *const threadSafeHandle, void *const pointer)
 Frees memory allocated by a thread-safe shinyAllocator instance. More...
 
SHINY_STATUS shinyDeinitThreadSafe (shinyAllocatorThreadSafeInstance *const threadSafeHandle)
 Deinitializes a thread-safe shinyAllocator instance. More...
 

Macro Definition Documentation

◆ SHINYALLOCATOR_ALIGNMENT

#define SHINYALLOCATOR_ALIGNMENT   (sizeof(void *) * 4U)

Memory alignment based on platform pointer (8/16/32)

◆ SHINYALLOCATOR_VERSION_MAJOR

#define SHINYALLOCATOR_VERSION_MAJOR   1

static version number

◆ SHINYALLOCATOR_VERSION_MINOR

#define SHINYALLOCATOR_VERSION_MINOR   0

Typedef Documentation

◆ SHINY_STATUS

typedef int_fast8_t SHINY_STATUS

◆ shinyAllocatorInstance

encapsulation of the structure instance

◆ shinyAllocatorThreadSafeInstance

Function Documentation

◆ shinyAllocate()

void* shinyAllocate ( shinyAllocatorInstance *const  handle,
const size_t  amount 
)

Allocated the requested memory to the given the pool handle, returns NULL if it fails.

Parameters
handleallocater handle to the pool.
sizethe requested allocation size.
Note
may cause integer-overflow for bigger sizes. It's recommended keep overall allocated bytes less than SIZE_MAX/2-1.

◆ shinyAllocateThreadSafe()

void* shinyAllocateThreadSafe ( shinyAllocatorThreadSafeInstance *const  threadSafeHandle,
const size_t  amount 
)

Allocates memory from a thread-safe shinyAllocator instance.

Parameters
threadSafeHandleThread-safe shinyAllocator instance.
amountAmount of memory to allocate.
Returns
Pointer to the allocated memory.

◆ shinyDeinitThreadSafe()

SHINY_STATUS shinyDeinitThreadSafe ( shinyAllocatorThreadSafeInstance *const  threadSafeHandle)

Deinitializes a thread-safe shinyAllocator instance.

Parameters
threadSafeHandle

◆ shinyFree()

void shinyFree ( shinyAllocatorInstance *const  handle,
void *const  pointer 
)

Frees the memory allocated to the given the pool handle.

Parameters
handleallocator handle to the pool.
pointerpointer to the allocated memory.

◆ shinyFreeThreadSafe()

SHINY_STATUS shinyFreeThreadSafe ( shinyAllocatorThreadSafeInstance *const  threadSafeHandle,
void *const  pointer 
)

Frees memory allocated by a thread-safe shinyAllocator instance.

Parameters
threadSafeHandleThread-safe shinyAllocator instance.
pointerPointer to the memory to be freed.

◆ shinyGetDiagnostics()

shinyAllocatorDiagnostics shinyGetDiagnostics ( shinyAllocatorInstance handle)
Parameters
handlepointer
Returns
current diagnostics

◆ shinyGetDiagnosticsThreadSafe()

shinyAllocatorDiagnostics shinyGetDiagnosticsThreadSafe ( shinyAllocatorThreadSafeInstance *const  threadSafeHandle)

Thread-safe wrapper for shinyGetDiagnostics().

Parameters
threadSafeHandleThread-safe shinyAllocator instance.
Returns
Diagnostics for the shinyAllocator instance.

◆ shinyInit()

shinyAllocatorInstance* shinyInit ( void *const  base,
const size_t  size 
)

Initializes the shinyAllocator for the given base pointer and size.

Parameters
basebase pointer for the pool, it should be aligned to SHINYALLOCATOR_ALIGNMENT.
sizesize of the pool, this parameter should not exceed SIZE_MAX/2.

allocator occupy 40+ bytes (up to 600 bytes depending on architecture) of the pool for holding its configuration.

Returns
NULL if the pool is not sufficient for the given size otherwise returns a pointer to the newly initialized allocator.
Note
An initialized any resources, hence you can discard it without any de-initialization if it is not needed.

◆ shinyInitThreadSafe()

shinyAllocatorThreadSafeInstance* shinyInitThreadSafe ( void *const  base,
const size_t  size 
)

Initializes a thread-safe shinyAllocator instance.

Parameters
baseBase address for the shinyAllocator instance.
sizeSize of the shinyAllocator instance.
Returns
Thread-safe shinyAllocator instance.

◆ sizeof_shinyAllocatorInstance()

size_t sizeof_shinyAllocatorInstance ( void  )
Returns
size of the shinyAllocatorInstance

◆ sizeof_shinyAllocatorThreadSafeInstance()

size_t sizeof_shinyAllocatorThreadSafeInstance ( void  )