CppELib 1.7.0
Loading...
Searching...
No Matches
TestDoubleFixedMemoryPoolFactory.h
Go to the documentation of this file.
1#ifndef TEST_DOUBLE_OS_WRAPPER_TEST_DOUBLE_FIXED_MEMORY_POOL_FACTORY_H_INCLUDED
2#define TEST_DOUBLE_OS_WRAPPER_TEST_DOUBLE_FIXED_MEMORY_POOL_FACTORY_H_INCLUDED
3
6#include <cstdlib>
7
8namespace TestDoubleOSWrapper {
9
11protected:
12 std::size_t m_blockSize;
13 std::size_t m_memoryPoolSize;
15
16public:
23
24 void setCreateArgs(std::size_t blockSize, std::size_t memoryPoolSize, void* memoryPoolAddress)
25 {
26 m_blockSize = blockSize;
27 m_memoryPoolSize = memoryPoolSize;
28 m_memoryPoolAddress = memoryPoolAddress;
29 }
30
32 {
33 }
34
35 virtual void* allocate()
36 {
37 return std::malloc(m_blockSize);
38 }
39
40 virtual void deallocate(void* p)
41 {
42 std::free(p);
43 }
44
45 virtual std::size_t getBlockSize() const
46 {
47 return m_blockSize;
48 }
49};
50
51template <typename T = TestDoubleFixedMemoryPool>
53public:
56
57 virtual OSWrapper::FixedMemoryPool* create(std::size_t blockSize, std::size_t memoryPoolSize, void* memoryPoolAddress)
58 {
59 T* obj = new T();
60 obj->setCreateArgs(blockSize, memoryPoolSize, memoryPoolAddress);
61 return obj;
62 }
63
65 {
66 delete static_cast<T*>(p);
67 }
68
69 virtual std::size_t getRequiredMemorySize(std::size_t blockSize, std::size_t numBlocks)
70 {
71 return blockSize * numBlocks;
72 }
73
74private:
77};
78
79}
80
81#endif // TEST_DOUBLE_OS_WRAPPER_TEST_DOUBLE_FIXED_MEMORY_POOL_FACTORY_H_INCLUDED
Definition FixedMemoryPoolFactory.h:10
Abstract class that has functions of common RTOS's fixed-size memory pool.
Definition FixedMemoryPool.h:23
Definition TestDoubleFixedMemoryPoolFactory.h:52
virtual std::size_t getRequiredMemorySize(std::size_t blockSize, std::size_t numBlocks)
Definition TestDoubleFixedMemoryPoolFactory.h:69
TestDoubleFixedMemoryPoolFactory()
Definition TestDoubleFixedMemoryPoolFactory.h:54
virtual OSWrapper::FixedMemoryPool * create(std::size_t blockSize, std::size_t memoryPoolSize, void *memoryPoolAddress)
Definition TestDoubleFixedMemoryPoolFactory.h:57
virtual ~TestDoubleFixedMemoryPoolFactory()
Definition TestDoubleFixedMemoryPoolFactory.h:55
virtual void destroy(OSWrapper::FixedMemoryPool *p)
Definition TestDoubleFixedMemoryPoolFactory.h:64
Definition TestDoubleFixedMemoryPoolFactory.h:10
std::size_t m_blockSize
Definition TestDoubleFixedMemoryPoolFactory.h:12
void setCreateArgs(std::size_t blockSize, std::size_t memoryPoolSize, void *memoryPoolAddress)
Definition TestDoubleFixedMemoryPoolFactory.h:24
void * m_memoryPoolAddress
Definition TestDoubleFixedMemoryPoolFactory.h:14
TestDoubleFixedMemoryPool()
Definition TestDoubleFixedMemoryPoolFactory.h:17
virtual ~TestDoubleFixedMemoryPool()
Definition TestDoubleFixedMemoryPoolFactory.h:31
std::size_t m_memoryPoolSize
Definition TestDoubleFixedMemoryPoolFactory.h:13
virtual void deallocate(void *p)
Release the allocated block.
Definition TestDoubleFixedMemoryPoolFactory.h:40
virtual void * allocate()
Allocate a block from this FixedMemoryPool.
Definition TestDoubleFixedMemoryPoolFactory.h:35
virtual std::size_t getBlockSize() const
Get the block size.
Definition TestDoubleFixedMemoryPoolFactory.h:45
Implementation of OSWrapper for Test Double.
Definition TestDoubleEventFlagFactory.h:7