| detalloc: Deterministic Real-Time Allocator $PROJECT_NUMBER
    C99 constant-time pool allocator for hard real-time | 
Detalloc — Phase 1: Single-Pool, Constant-Time Allocator. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h> Include dependency graph for detalloc.h:
 Include dependency graph for detalloc.h: This graph shows which files directly or indirectly include this file:
 This graph shows which files directly or indirectly include this file:Go to the source code of this file.
| Data Structures | |
| struct | det_config_t | 
| Phase-1 configuration: one fixed-size pool.  More... | |
| Macros | |
| #define | DETALLOC_VERSION_MAJOR 0 | 
| #define | DETALLOC_VERSION_MINOR 1 | 
| #define | DETALLOC_VERSION_PATCH 0 | 
| #define | DET_ALIGN_UP(sz, a) (((sz) + ((a)-1)) & ~((a)-1)) | 
| #define | DET_NEW(alloc, type) ((type *)det_alloc((alloc))) | 
| #define | DET_FREE(alloc, ptr) | 
| Typedefs | |
| typedef struct det_allocator | det_allocator_t | 
| Opaque allocator handle (single pool in Phase 1). | |
| Enumerations | |
| enum | det_error_t { DET_OK = 0 , DET_ERR_INVALID_PARAM , DET_ERR_OUT_OF_MEMORY , DET_ERR_POOL_FULL , DET_ERR_INVALID_PTR , DET_ERR_NOT_INITIALIZED } | 
| Error/status codes returned by Detalloc.  More... | |
| Functions | |
| DETALLOC_API size_t | det_alloc_size (const det_config_t *config) | 
| Compute required buffer size for a given Phase-1 config. | |
| DETALLOC_API det_allocator_t * | det_alloc_init (void *memory, size_t size, const det_config_t *config) | 
| Initialize allocator over a user-provided memory buffer. | |
| DETALLOC_API void * | det_alloc (det_allocator_t *alloc) | 
| Allocate a single fixed-size block. | |
| DETALLOC_API void * | det_calloc (det_allocator_t *alloc) | 
| Allocate a zero-initialized block. | |
| DETALLOC_API void | det_free (det_allocator_t *alloc, void *ptr) | 
| Free a previously allocated block (NULL is a no-op). | |
| DETALLOC_API size_t | det_alloc_usable_size (det_allocator_t *alloc, void *ptr) | 
| Return usable size of a block. | |
| DETALLOC_API void | det_alloc_destroy (det_allocator_t *alloc) | 
| Destroy allocator structures (metadata cleanup only). | |
| DETALLOC_API det_config_t | det_default_config (void) | 
| Return a sensible Phase-1 default config. | |
| DETALLOC_API const char * | det_version_string (void) | 
| Get library version string "major.minor.patch". | |
Detalloc — Phase 1: Single-Pool, Constant-Time Allocator.
Minimal API for a fixed-size, bitmap-based pool allocator with O(1) alloc/free. Designed for hard real-time use; no syscalls after init; uses user-provided memory.
Definition in file detalloc.h.
| #define DET_ALIGN_UP | ( | sz, | |
| a | |||
| ) | (((sz) + ((a)-1)) & ~((a)-1)) | 
Default block size for Phase 1 (can be overridden at init-time). Default alignment for returned blocks (power of two). Align up helper.
Definition at line 80 of file detalloc.h.
| #define DET_FREE | ( | alloc, | |
| ptr | |||
| ) | 
Free and null a pointer.
Definition at line 243 of file detalloc.h.
| #define DET_NEW | ( | alloc, | |
| type | |||
| ) | ((type *)det_alloc((alloc))) | 
Allocate a typed object (one fixed-size block must fit it).
Definition at line 240 of file detalloc.h.
| #define DETALLOC_VERSION_MAJOR 0 | 
Definition at line 61 of file detalloc.h.
| #define DETALLOC_VERSION_MINOR 1 | 
Definition at line 62 of file detalloc.h.
| #define DETALLOC_VERSION_PATCH 0 | 
Definition at line 63 of file detalloc.h.
| typedef struct det_allocator det_allocator_t | 
Opaque allocator handle (single pool in Phase 1).
Implementation maintains:
Definition at line 110 of file detalloc.h.
| enum det_error_t | 
Error/status codes returned by Detalloc.
Definition at line 89 of file detalloc.h.
| DETALLOC_API void * det_alloc | ( | det_allocator_t * | alloc | ) | 
Allocate a single fixed-size block.
| alloc | Allocator handle | 
| DETALLOC_API void det_alloc_destroy | ( | det_allocator_t * | alloc | ) | 
Destroy allocator structures (metadata cleanup only).
The user-provided memory buffer is not freed.
| alloc | Allocator handle | 
| DETALLOC_API det_allocator_t * det_alloc_init | ( | void * | memory, | 
| size_t | size, | ||
| const det_config_t * | config | ||
| ) | 
Initialize allocator over a user-provided memory buffer.
No dynamic allocation; all metadata lives inside memory.
| memory | Pointer to pre-allocated memory buffer (non-NULL) | 
| size | Size of memory buffer in bytes (>= det_alloc_size(config)) | 
| config | Non-NULL Phase-1 configuration | 
| DETALLOC_API size_t det_alloc_size | ( | const det_config_t * | config | ) | 
Compute required buffer size for a given Phase-1 config.
Calculates metadata + bitmap + aligned payload area.
| config | Non-NULL configuration | 
| DETALLOC_API size_t det_alloc_usable_size | ( | det_allocator_t * | alloc, | 
| void * | ptr | ||
| ) | 
Return usable size of a block.
| alloc | Allocator handle | 
| ptr | Pointer to allocated block | 
| DETALLOC_API void * det_calloc | ( | det_allocator_t * | alloc | ) | 
Allocate a zero-initialized block.
| alloc | Allocator handle | 
| DETALLOC_API det_config_t det_default_config | ( | void | ) | 
Return a sensible Phase-1 default config.
Defaults:
Definition at line 5 of file detalloc.c.
References det_config_t::align, det_config_t::block_size, det_config_t::num_blocks, and det_config_t::thread_safe.
| DETALLOC_API void det_free | ( | det_allocator_t * | alloc, | 
| void * | ptr | ||
| ) | 
Free a previously allocated block (NULL is a no-op).
| alloc | Allocator handle | 
| ptr | Pointer returned by det_alloc()/det_calloc() | 
ptr was not allocated by this allocator. | DETALLOC_API const char * det_version_string | ( | void | ) | 
Get library version string "major.minor.patch".
Definition at line 3 of file detalloc.c.