OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
memory.hpp
1#ifndef QOS_CPP_MEMORY
2#define QOS_CPP_MEMORY
3
4#include "include/types.hpp"
5
6#ifndef Q_BYTE_ALIGNMENT
7 #define Q_BYTE_ALIGNMENT ( 8 )
8#endif
9
10#if ( ( Q_BYTE_ALIGNMENT != 1 ) && ( Q_BYTE_ALIGNMENT != 2 ) && ( Q_BYTE_ALIGNMENT != 4 ) && ( Q_BYTE_ALIGNMENT != 8 ) )
11 #error Q_BYTE_ALIGNMENT value not allowed, use only 1,2,4 or 8(default).
12#endif
13
14namespace qOS {
15
19 namespace mem {
20
27 using address_t = size_t;
28 struct blockConnect_t {
29 blockConnect_t *next{ nullptr };
30 size_t blockSize{ 0U };
31 };
42 class pool {
43 private:
44 blockConnect_t *end{ nullptr };
45 blockConnect_t start;
46 uint8_t *poolMemory{ nullptr };
47 size_t poolMemSize{ 0U };
48 size_t freeBytesRemaining{ 0U };
49 void insertBlockIntoFreeList( blockConnect_t *xBlock ) noexcept;
50 void init( void ) noexcept;
51 pool( pool const& ) = delete;
52 void operator=( pool const& ) = delete;
53 public:
55 virtual ~pool() {}
64 inline pool( void *pArea, const size_t pSize ) noexcept {
65 (void)setup( pArea, pSize );
66 }
76 bool setup( void *pArea, const size_t pSize ) noexcept;
92 void free( void *ptr ) noexcept;
103 void* alloc( size_t pSize ) noexcept;
109 size_t getFreeSize( void ) const noexcept;
110 };
111
113 }
114}
115
116 #if ( Q_DEFAULT_HEAP_SIZE >= 64 )
117 void * operator new( size_t size);
118 void * operator new[]( size_t size);
119
120 void operator delete(void * ptr) noexcept;
121 void operator delete[](void * ptr) noexcept;
122
123 void operator delete(void* ptr, void* place) noexcept;
124 void operator delete[](void* ptr, void* place) noexcept;
125 #endif /*Q_USE_MEM_ALLOCATION_SCHEME*/
126
127#endif /*QOS_CPP_MEMORY*/
A Memory Pool object.
Definition memory.hpp:42
bool setup(void *pArea, const size_t pSize) noexcept
Initializes a memory pool instance. This function should be called once before any heap memory reques...
pool(void *pArea, const size_t pSize) noexcept
Initializes a memory pool instance.
Definition memory.hpp:64
void * alloc(size_t pSize) noexcept
Allocate a block of memory that is pSize bytes large. If the requested memory can be allocated,...
void free(void *ptr) noexcept
Deallocates the space previously allocated by mem::pool::alloc(). Deallocation will be performed in t...
size_t getFreeSize(void) const noexcept
Returns the total amount of heap space that remains unallocated for the memory pool.
OS/Kernel interfaces.
Definition bytebuffer.hpp:7