LibJuno 0.42.0
LibJuno is a lightweight C99 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
memory_block.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
27#ifndef JUNO_MEMORY_BLOCK_H
28#define JUNO_MEMORY_BLOCK_H
29#include "juno/module.h"
30#include "juno/status.h"
32#ifdef __cplusplus
33extern "C"
34{
35#endif
36
41
42#ifdef __cplusplus
43#define JUNO_MEMORY_BLOCK(name, type, length) static type name[length] = {}
44#else
45#define JUNO_MEMORY_BLOCK(name, type, length) static type name[length] = {0}
46#endif
47
51#ifdef __cplusplus
52#define JUNO_MEMORY_BLOCK_METADATA(name, length) static JUNO_MEMORY_BLOCK_METADATA_T name[length] = {}
53#else
54#define JUNO_MEMORY_BLOCK_METADATA(name, length) static JUNO_MEMORY_BLOCK_METADATA_T name[length] = {0}
55#endif
56
57
59typedef struct JUNO_MEMORY_BLOCK_TAG JUNO_MEMORY_BLOCK_T;
60typedef struct JUNO_MEMORY_ALLOC_BLOCK_TAG JUNO_MEMORY_ALLOC_BLOCK_T;
61
62struct JUNO_MEMORY_ALLOC_BLOCK_TAG JUNO_MODULE_DERIVE(JUNO_MEMORY_ALLOC_ROOT_T,
63 uint8_t *pvMemory;
65 size_t zTypeSize;
66 size_t zLength;
67 size_t zUsed;
68 size_t zFreed;
69);
70
71#ifndef JUNO_MEMORY_CUSTOM
82 JUNO_MEMORY_ALLOC_BLOCK_T tJunoMemoryBlock;
83);
84#endif
85
97 void *pvMemory,
99 size_t zTypeSize,
100 size_t zLength,
101 JUNO_FAILURE_HANDLER_T pfcnFailureHandler,
102 JUNO_USER_DATA_T *pvFailureUserData
103);
104#ifdef __cplusplus
105}
106#endif
107#endif // JUNO_MEMORY_BLOCK_H
108
union JUNO_MEMORY_ALLOC_TAG JUNO_MEMORY_ALLOC_T
Definition memory_api.h:63
struct JUNO_MEMORY_ALLOC_ROOT_TAG JUNO_MEMORY_ALLOC_ROOT_T
Definition memory_api.h:64
struct JUNO_MEMORY_BLOCK_TAG JUNO_MEMORY_BLOCK_T
Definition memory_block.h:59
JUNO_STATUS_T JunoMemory_BlockApi(JUNO_MEMORY_ALLOC_T *ptJunoMemory, void *pvMemory, JUNO_MEMORY_BLOCK_METADATA_T *ptMetadata, size_t zTypeSize, size_t zLength, JUNO_FAILURE_HANDLER_T pfcnFailureHandler, JUNO_USER_DATA_T *pvFailureUserData)
Initializes a memory block for allocation. Sets up a memory block with an associated free stack for m...
Definition juno_memory_block.c:205
struct JUNO_MEMORY_ALLOC_BLOCK_TAG JUNO_MEMORY_ALLOC_BLOCK_T
Definition memory_block.h:60
#define JUNO_MODULE(API_T, ROOT_T,...)
Definition module.h:161
#define JUNO_MODULE_DERIVE(ROOT_T,...)
Definition module.h:203
void(* JUNO_FAILURE_HANDLER_T)(JUNO_STATUS_T tStatus, const char *pcCustomMessage, JUNO_USER_DATA_T *pvUserData)
Definition status.h:44
enum JUNO_STATUS_TAG JUNO_STATUS_T
void JUNO_USER_DATA_T
Definition status.h:43
Definition memory_api.h:69
The memory metadata.
Definition memory_api.h:45