Embedded Template Library
1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
fixed_sized_memory_block_allocator.h
Go to the documentation of this file.
1
2
3
/******************************************************************************
4
The MIT License(MIT)
5
6
Embedded Template Library.
7
https://github.com/ETLCPP/etl
8
https://www.etlcpp.com
9
10
Copyright(c) 2021 John Wellbelove
11
12
Permission is hereby granted, free of charge, to any person obtaining a copy
13
of this software and associated documentation files(the "Software"), to deal
14
in the Software without restriction, including without limitation the rights
15
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16
copies of the Software, and to permit persons to whom the Software is
17
furnished to do so, subject to the following conditions :
18
19
The above copyright notice and this permission notice shall be included in all
20
copies or substantial portions of the Software.
21
22
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
SOFTWARE.
29
******************************************************************************/
30
31
#ifndef ETL_FIXED_MEMORY_BLOCK_POOL_INCLUDED
32
#define ETL_FIXED_MEMORY_BLOCK_POOL_INCLUDED
33
34
#include "
platform.h
"
35
#include "
alignment.h
"
36
#include "
generic_pool.h
"
37
#include "
imemory_block_allocator.h
"
38
39
namespace
etl
40
{
41
//*************************************************************************
44
//*************************************************************************
45
template
<
size_t
VBlock_Size,
size_t
VAlignment,
size_t
VSize>
46
class
fixed_sized_memory_block_allocator
:
public
imemory_block_allocator
47
{
48
public
:
49
50
static
ETL_CONSTANT
size_t
Block_Size = VBlock_Size;
51
static
ETL_CONSTANT
size_t
Alignment = VAlignment;
52
static
ETL_CONSTANT
size_t
Size = VSize;
53
54
//*************************************************************************
56
//*************************************************************************
57
fixed_sized_memory_block_allocator
() {}
58
59
protected
:
60
61
//*************************************************************************
63
//*************************************************************************
64
virtual
void
*
allocate_block
(
size_t
required_size,
size_t
required_alignment) ETL_OVERRIDE
65
{
66
if
((required_alignment <= Alignment) && (required_size <= Block_Size) && !pool.full())
67
{
68
return
pool.template
allocate<block>
();
69
}
70
else
71
{
72
return
ETL_NULLPTR;
73
}
74
}
75
76
//*************************************************************************
78
//*************************************************************************
79
virtual
bool
release_block
(
const
void
*
const
pblock) ETL_OVERRIDE
80
{
81
if
(pool.is_in_pool(pblock))
82
{
83
pool.release(
static_cast<
const
block* const
>
(pblock));
84
return
true
;
85
}
86
else
87
{
88
return
false
;
89
}
90
}
91
92
//*************************************************************************
94
//*************************************************************************
95
virtual
bool
is_owner_of_block
(
const
void
*
const
pblock)
const
ETL_OVERRIDE
96
{
97
return
pool.is_in_pool(pblock);
98
}
99
100
private
:
101
103
struct
block
104
{
105
char
data
[Block_Size];
106
};
107
109
etl::generic_pool<Block_Size, Alignment, Size>
pool;
110
};
111
112
template
<
size_t
VBlock_Size,
size_t
VAlignment,
size_t
VSize>
113
ETL_CONSTANT
size_t
fixed_sized_memory_block_allocator<VBlock_Size, VAlignment, VSize>::Block_Size;
114
115
template
<
size_t
VBlock_Size,
size_t
VAlignment,
size_t
VSize>
116
ETL_CONSTANT
size_t
fixed_sized_memory_block_allocator<VBlock_Size, VAlignment, VSize>::Alignment;
117
118
template
<
size_t
VBlock_Size,
size_t
VAlignment,
size_t
VSize>
119
ETL_CONSTANT
size_t
fixed_sized_memory_block_allocator<VBlock_Size, VAlignment, VSize>::Size;
120
}
// namespace etl
121
122
#endif
alignment.h
etl::fixed_sized_memory_block_allocator::allocate_block
virtual void * allocate_block(size_t required_size, size_t required_alignment) ETL_OVERRIDE
The overridden virtual function to allocate a block.
Definition
fixed_sized_memory_block_allocator.h:64
etl::fixed_sized_memory_block_allocator::is_owner_of_block
virtual bool is_owner_of_block(const void *const pblock) const ETL_OVERRIDE
Returns true if the allocator is the owner of the block.
Definition
fixed_sized_memory_block_allocator.h:95
etl::fixed_sized_memory_block_allocator::fixed_sized_memory_block_allocator
fixed_sized_memory_block_allocator()
Default constructor.
Definition
fixed_sized_memory_block_allocator.h:57
etl::fixed_sized_memory_block_allocator::release_block
virtual bool release_block(const void *const pblock) ETL_OVERRIDE
The overridden virtual function to release a block.
Definition
fixed_sized_memory_block_allocator.h:79
etl::imemory_block_allocator::imemory_block_allocator
imemory_block_allocator()
Default constructor.
Definition
imemory_block_allocator.h:50
etl::imemory_block_allocator::allocate
void * allocate(size_t required_size, size_t required_alignment)
Definition
imemory_block_allocator.h:57
generic_pool.h
etl::generic_pool
Definition
generic_pool.h:56
imemory_block_allocator.h
etl
Definition
absolute.h:40
etl::data
ETL_CONSTEXPR TContainer::pointer data(TContainer &container)
Definition
iterator.h:1470
platform.h
include
etl
fixed_sized_memory_block_allocator.h
Generated on
for Embedded Template Library by
1.17.0