libs
libuavcan
libuavcan
src
uc_dynamic_memory.cpp
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2014 Pavel Kirienko <pavel.kirienko@gmail.com>
3
*/
4
5
#include <
uavcan/dynamic_memory.hpp
>
6
7
namespace
uavcan
8
{
9
/*
10
* LimitedPoolAllocator
11
*/
12
void
*
LimitedPoolAllocator::allocate
(
std::size_t
size)
13
{
14
if
(
used_blocks_
<
max_blocks_
)
15
{
16
used_blocks_
++;
17
return
allocator_
.
allocate
(size);
18
}
19
else
20
{
21
return
UAVCAN_NULLPTR
;
22
}
23
}
24
25
void
LimitedPoolAllocator::deallocate
(
const
void
* ptr)
26
{
27
allocator_
.
deallocate
(ptr);
28
29
UAVCAN_ASSERT
(
used_blocks_
> 0);
30
if
(
used_blocks_
> 0)
31
{
32
used_blocks_
--;
33
}
34
}
35
36
uint16_t
LimitedPoolAllocator::getBlockCapacity
()
const
37
{
38
return
min
(
max_blocks_
,
allocator_
.
getBlockCapacity
());
39
}
40
41
}
UAVCAN_NULLPTR
#define UAVCAN_NULLPTR
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:51
std::size_t
unsigned long size_t
Definition:
coverity_scan_model.cpp:19
uavcan::IPoolAllocator::getBlockCapacity
virtual uint16_t getBlockCapacity() const =0
dynamic_memory.hpp
uavcan::LimitedPoolAllocator::allocator_
IPoolAllocator & allocator_
Definition:
dynamic_memory.hpp:114
uavcan::IPoolAllocator::allocate
virtual void * allocate(std::size_t size)=0
uavcan::uint16_t
std::uint16_t uint16_t
Definition:
std.hpp:25
uavcan::LimitedPoolAllocator::max_blocks_
const uint16_t max_blocks_
Definition:
dynamic_memory.hpp:115
uavcan::LimitedPoolAllocator::allocate
virtual void * allocate(std::size_t size)
Definition:
uc_dynamic_memory.cpp:12
uavcan::IPoolAllocator::deallocate
virtual void deallocate(const void *ptr)=0
uavcan::LimitedPoolAllocator::getBlockCapacity
virtual uint16_t getBlockCapacity() const
Definition:
uc_dynamic_memory.cpp:36
uavcan::min
const UAVCAN_EXPORT T & min(const T &a, const T &b)
Definition:
templates.hpp:281
uavcan::LimitedPoolAllocator::deallocate
virtual void deallocate(const void *ptr)
Definition:
uc_dynamic_memory.cpp:25
uavcan
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:204
uavcan::LimitedPoolAllocator::used_blocks_
uint16_t used_blocks_
Definition:
dynamic_memory.hpp:116
UAVCAN_ASSERT
#define UAVCAN_ASSERT(x)
Definition:
libuavcan/libuavcan/include/uavcan/build_config.hpp:184
uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:03