OS  v7.3.3
Documentation
Loading...
Searching...
No Matches
qmemmang.h
1
8#ifndef QMEMMANG_H
9 #define QMEMMANG_H
10
11 #include "qtypes.h"
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17
18 #ifndef Q_MEMORY_MANAGER
19 #define Q_MEMORY_MANAGER ( 1 )
20 #endif
21
22 #if ( Q_MEMORY_MANAGER == 1 )
23
24 #ifndef Q_BYTE_ALIGNMENT
25 #define Q_BYTE_ALIGNMENT ( 8 )
26 #endif
27
28 #ifndef Q_DEFAULT_HEAP_SIZE
29 #define Q_DEFAULT_HEAP_SIZE ( 512 )
30 #endif
31
32 #if ( Q_DEFAULT_HEAP_SIZE < 64 )
33 #error Q_DEFAULT_HEAP_SIZE it is too small. Min(64).
34 #endif
35
36 #if ( ( Q_BYTE_ALIGNMENT != 1 ) && ( Q_BYTE_ALIGNMENT != 2 ) && ( Q_BYTE_ALIGNMENT != 4 ) && ( Q_BYTE_ALIGNMENT != 8 ) )
37 #error Q_BYTE_ALIGNMENT value not allowed, use only 1,2,4 or 8(default).
38 #endif
39
40
46 /* List to connect the free blocks in order of their memory address. */
48 typedef struct _qMemMang_BlockConnect_s { // skipcq: CXX-E2000
49 struct _qMemMang_BlockConnect_s *next; /*< Points to the next free block in the list*/
50 size_t blockSize; /*< The size of the free block*/
51 }
52 qMemMang_BlockConnect_t;
74 typedef struct _qMemMang_Pool_s { // skipcq: CXX-E2000
76 struct _qMemMang_Pool_Private_s { // skipcq: CXX-E2000
77 qMemMang_BlockConnect_t *end; /*< Points to the last block of the list. */
78 qUINT8_t *poolMemory; /*< Points to the beginning of the heap area statically allocated. */
79 size_t poolMemSize; /*< The size of the memory block pointed by "heap". */
80 size_t freeBytesRemaining; /*< The number of free bytes in the heap. */
81 qMemMang_BlockConnect_t start; /*< The first block of the heap. */
82 }
83 qPrivate;
85 }
86 qMemMang_Pool_t;
87
98 qBool_t qMemMang_Pool_Setup( qMemMang_Pool_t * const mPool,
99 void* pArea,
100 const size_t pSize );
101
108 qBool_t qMemMang_Pool_Select( qMemMang_Pool_t * const mPool );
109
117 size_t qMemMang_Get_FreeSize( const qMemMang_Pool_t *mPool );
118
130 void* qMemMang_Allocate( qMemMang_Pool_t *mPool,
131 size_t pSize );
132
149 qBool_t qMemMang_Free( qMemMang_Pool_t *mPool,
150 void *ptr );
151
166 void* qMalloc( size_t mSize );
167
185 void qFree( void *ptr );
186
189 #endif
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195#endif
qUINT8_t qBool_t
A type to instantiate an OS boolean variable.
Definition qtypes.h:139
uint8_t qUINT8_t
Unsigned integer type with width of exactly 8 bits respectively.
Definition qtypes.h:44