Classes | Public Member Functions | Static Public Attributes | Private Attributes | List of all members
uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer > Class Template Reference

#include <dynamic_memory.hpp>

Inheritance diagram for uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >:
Inheritance graph
[legend]

Classes

union  Node
 

Public Member Functions

void * allocate (std::size_t size)
 
virtual void * allocate (std::size_t size)
 
void deallocate (const void *ptr)
 
virtual void deallocate (const void *ptr)
 
virtual uint16_t getBlockCapacity () const
 
uint16_t getNumFreeBlocks () const
 
uint16_t getNumUsedBlocks () const
 
uint16_t getPeakNumUsedBlocks () const
 
 PoolAllocator ()
 
- Public Member Functions inherited from uavcan::IPoolAllocator
virtual ~IPoolAllocator ()
 

Static Public Attributes

static const uint16_t NumBlocks = PoolSize / BlockSize
 

Private Attributes

Nodefree_list_
 
uint16_t max_used_
 
union {
   long double   _aligner1
 
   long long   _aligner2
 
   Node   _aligner3
 
   uint8_t   bytes [PoolSize]
 
pool_
 
uint16_t used_
 

Additional Inherited Members

- Private Member Functions inherited from uavcan::Noncopyable
 Noncopyable ()
 
 ~Noncopyable ()
 

Detailed Description

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
class uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >

Classic implementation of a pool allocator (Meyers).

The allocator can be made thread-safe (optional) by means of providing a RAII-lock type via the second template argument. The allocator uses the lock only to access the shared state, therefore critical sections are only a few cycles long, which implies that it should be acceptable to use hardware IRQ disabling instead of a mutex for performance reasons. For example, an IRQ-based RAII-lock type can be implemented as follows: struct RaiiSynchronizer { RaiiSynchronizer() { __disable_irq(); } ~RaiiSynchronizer() { __enable_irq(); } };

Definition at line 51 of file dynamic_memory.hpp.

Constructor & Destructor Documentation

◆ PoolAllocator()

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer >
uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::PoolAllocator

Definition at line 142 of file dynamic_memory.hpp.

Member Function Documentation

◆ allocate() [1/2]

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
void* uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::allocate ( std::size_t  size)
inlinevirtual

Implements uavcan::IPoolAllocator.

Definition at line 34 of file coverity_scan_model.cpp.

◆ allocate() [2/2]

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer >
void * uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::allocate ( std::size_t  size)
virtual

Implements uavcan::IPoolAllocator.

Definition at line 160 of file dynamic_memory.hpp.

◆ deallocate() [1/2]

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
void uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::deallocate ( const void *  ptr)
inlinevirtual

Implements uavcan::IPoolAllocator.

Definition at line 39 of file coverity_scan_model.cpp.

◆ deallocate() [2/2]

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer >
void uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::deallocate ( const void *  ptr)
virtual

Implements uavcan::IPoolAllocator.

Definition at line 185 of file dynamic_memory.hpp.

◆ getBlockCapacity()

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
virtual uint16_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::getBlockCapacity ( ) const
inlinevirtual

Returns the maximum number of blocks this allocator can allocate.

Implements uavcan::IPoolAllocator.

Definition at line 80 of file dynamic_memory.hpp.

◆ getNumFreeBlocks()

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
uint16_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::getNumFreeBlocks ( ) const
inline

Definition at line 91 of file dynamic_memory.hpp.

◆ getNumUsedBlocks()

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
uint16_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::getNumUsedBlocks ( ) const
inline

Return the number of blocks that are currently allocated/unallocated.

Definition at line 85 of file dynamic_memory.hpp.

◆ getPeakNumUsedBlocks()

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
uint16_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::getPeakNumUsedBlocks ( ) const
inline

Returns the maximum number of blocks that were ever allocated at the same time.

Definition at line 101 of file dynamic_memory.hpp.

Member Data Documentation

◆ _aligner1

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
long double uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::_aligner1

Definition at line 64 of file dynamic_memory.hpp.

◆ _aligner2

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
long long uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::_aligner2

Definition at line 65 of file dynamic_memory.hpp.

◆ _aligner3

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
Node uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::_aligner3

Definition at line 66 of file dynamic_memory.hpp.

◆ bytes

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
uint8_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::bytes[PoolSize]

Definition at line 63 of file dynamic_memory.hpp.

◆ free_list_

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
Node* uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::free_list_
private

Definition at line 60 of file dynamic_memory.hpp.

◆ max_used_

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
uint16_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::max_used_
private

Definition at line 70 of file dynamic_memory.hpp.

◆ NumBlocks

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer >
const uint16_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::NumBlocks = PoolSize / BlockSize
static

Definition at line 73 of file dynamic_memory.hpp.

◆ pool_

union { ... } uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::pool_

◆ used_

template<std::size_t PoolSize, uint8_t BlockSize, typename RaiiSynchronizer = char>
uint16_t uavcan::PoolAllocator< PoolSize, BlockSize, RaiiSynchronizer >::used_
private

Definition at line 69 of file dynamic_memory.hpp.


The documentation for this class was generated from the following files:


uavcan_communicator
Author(s):
autogenerated on Fri Dec 13 2024 03:10:05