LibJuno 0.1.0
LibJuno is a lightweight C99 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
memory_types.h
Go to the documentation of this file.
1#ifndef JUNO_MEMORY_H
2#define JUNO_MEMORY_H
3
4#include "juno/macros.h"
5#include <stddef.h>
6#include <stdint.h>
7#include "stddef.h"
8
9#ifdef __cplusplus
10extern "C" {
11#endif
12
17#define JUNO_MEMORY_BLOCK(name, type, length) \
18static type name[length] = {};
19
23#define JUNO_MEMORY_BLOCK_METADATA(name, length) \
24static JUNO_MEMORY_BLOCK_METADATA_T name[length] = {};
25
26#define JUNO_REF(name) REF##name
27#define JUNO_NEW_REF(name) JUNO_MEMORY_T *JUNO_REF(name)
28
33
34#ifndef JUNO_CUSTOM_ALLOC
36#endif
37
44
49
56
60{
62 void *pvAddr;
64 size_t zSize;
66 size_t iRefCount;
67};
68
69
70
84
85#ifndef JUNO_CUSTOM_ALLOC
93#endif
94
102static inline JUNO_MEMORY_T * Juno_MemoryGetRef(JUNO_MEMORY_T *ptMemory)
103{
104 if(ptMemory->iRefCount)
105 {
106 ptMemory->iRefCount += 1;
107 }
108 return ptMemory;
109}
110
118static inline void Juno_MemoryPutRef(JUNO_MEMORY_T *ptMemory)
119{
120 if(ptMemory->iRefCount)
121 {
122 ptMemory->iRefCount -= 1;
123 }
124}
125
126#ifdef __cplusplus
127}
128#endif
129#endif
130
enum JUNO_MEMORY_ALLOC_TYPE_TAG JUNO_MEMORY_ALLOC_TYPE_T
Enumeration of memory allocation types.
JUNO_MEMORY_ALLOC_TYPE_TAG
Enumeration of memory allocation types.
Definition memory_types.h:40
@ JUNO_MEMORY_ALLOC_TYPE_BLOCK
Block-based memory allocation.
Definition memory_types.h:42
@ JUNO_MEMORY_ALLOC_TYPE_RESERVED
Reserved allocation type.
Definition memory_types.h:41
Structure for memory allocation header. Contains general information including the type of allocation...
Definition memory_types.h:53
JUNO_MEMORY_ALLOC_TYPE_T tType
Type of memory allocation.
Definition memory_types.h:54
Definition memory_types.h:46
uint8_t * ptFreeMem
Definition memory_types.h:47
Structure representing a block-based memory allocator. Manages a fixed-size memory area along with as...
Definition memory_types.h:74
size_t zTypeSize
Size of each block element.
Definition memory_types.h:78
size_t zLength
Total number of blocks available.
Definition memory_types.h:79
DECLARE_FAILURE_HANDLER
Macro to declare a failure handler.
Definition memory_types.h:82
uint8_t * pvMemory
Pointer to the allocated memory area.
Definition memory_types.h:76
size_t zFreed
Current count of freed blocks in the free stack.
Definition memory_types.h:81
JUNO_MEMORY_BLOCK_METADATA_T * ptMetadata
Array of metadata for each block.
Definition memory_types.h:77
size_t zUsed
Current count of allocated blocks.
Definition memory_types.h:80
JUNO_MEMORY_ALLOC_HDR_T tHdr
Header indicating the allocation type.
Definition memory_types.h:75
Structure for an allocated memory segment. Describes the allocated memory with a pointer to the start...
Definition memory_types.h:60
void * pvAddr
Pointer to the allocated memory.
Definition memory_types.h:62
size_t iRefCount
The reference count for this memory.
Definition memory_types.h:66
size_t zSize
Size of the allocated memory, in bytes.
Definition memory_types.h:64
Union for a generic memory allocation. Accommodates various allocation types, currently including blo...
Definition memory_types.h:89
JUNO_MEMORY_BLOCK_T tBlock
Block-based allocation structure.
Definition memory_types.h:91
JUNO_MEMORY_ALLOC_HDR_T tHdr
Common header for any allocation type.
Definition memory_types.h:90