CppELib 1.7.0
Loading...
Searching...
No Matches
FixedMemoryPool.h
Go to the documentation of this file.
1#ifndef OS_WRAPPER_FIXED_MEMORY_POOL_H_INCLUDED
2#define OS_WRAPPER_FIXED_MEMORY_POOL_H_INCLUDED
3
4#include <cstddef>
5#include "Timeout.h"
6#include "OSWrapperError.h"
7
8namespace OSWrapper {
9
10class FixedMemoryPoolFactory;
11
18void registerFixedMemoryPoolFactory(FixedMemoryPoolFactory* factory);
19
24protected:
25 virtual ~FixedMemoryPool() {}
26
27public:
37 static FixedMemoryPool* create(std::size_t blockSize, std::size_t memoryPoolSize, void* memoryPoolAddress = 0);
38
45 static void destroy(FixedMemoryPool* p);
46
55 static std::size_t getRequiredMemorySize(std::size_t blockSize, std::size_t numBlocks);
56
61 virtual void* allocate() = 0;
62
69 virtual void deallocate(void* p) = 0;
70
75 virtual std::size_t getBlockSize() const = 0;
76
88 virtual Error allocateMemory(void** memory);
89
101 virtual Error tryAllocateMemory(void** memory);
102
117 virtual Error timedAllocateMemory(void** memory, Timeout tmout);
118
125 virtual std::size_t getNumberOfAvailableBlocks() const;
126
133 virtual std::size_t getMaxNumberOfBlocks() const;
134};
135
136}
137
138#endif // OS_WRAPPER_FIXED_MEMORY_POOL_H_INCLUDED
Abstract class that has functions of common RTOS's fixed-size memory pool.
Definition FixedMemoryPool.h:23
virtual Error timedAllocateMemory(void **memory, Timeout tmout)
Block the current thread until a memory block is allocated from this FixedMemoryPool but only within ...
Definition FixedMemoryPool.cpp:45
virtual ~FixedMemoryPool()
Definition FixedMemoryPool.h:25
static FixedMemoryPool * create(std::size_t blockSize, std::size_t memoryPoolSize, void *memoryPoolAddress=0)
Create a FixedMemoryPool object.
Definition FixedMemoryPool.cpp:14
virtual void * allocate()=0
Allocate a block from this FixedMemoryPool.
static std::size_t getRequiredMemorySize(std::size_t blockSize, std::size_t numBlocks)
Get the required total memory size for allocation of (blockSize * numBlocks)
Definition FixedMemoryPool.cpp:27
virtual std::size_t getBlockSize() const =0
Get the block size.
virtual Error allocateMemory(void **memory)
Block the current thread until a memory block is allocated from this FixedMemoryPool.
Definition FixedMemoryPool.cpp:33
static void destroy(FixedMemoryPool *p)
Destroy a FixedMemoryPool object.
Definition FixedMemoryPool.cpp:20
virtual std::size_t getNumberOfAvailableBlocks() const
Get the remaining number of available blocks in this FixedMemoryPool.
Definition FixedMemoryPool.cpp:52
virtual std::size_t getMaxNumberOfBlocks() const
Get the max number of blocks in this FixedMemoryPool.
Definition FixedMemoryPool.cpp:57
virtual void deallocate(void *p)=0
Release the allocated block.
virtual Error tryAllocateMemory(void **memory)
Try to allocate a memory block from this FixedMemoryPool without blocking.
Definition FixedMemoryPool.cpp:39
Value object for the timeout.
Definition Timeout.h:11
OSWrapper provides abstract C++ interface of common RTOS: thread, mutex, event flag,...
Definition EventFlag.cpp:5
void registerFixedMemoryPoolFactory(FixedMemoryPoolFactory *factory)
Register the FixedMemoryPoolFactory.
Definition FixedMemoryPool.cpp:9
Error
Kinds of errors of the OS objects.
Definition OSWrapperError.h:9