Base class for CachingAllocator implementations.
More...
#include <cheetah/data/detail/CachingAllocatorImplBase.h>
|
typedef std::multimap< std::size_t, T * > | FreeBlocksType |
|
typedef std::map< T *, std::size_t > | AllocatedBlocksType |
|
|
FreeBlocksType | _free_blocks |
|
AllocatedBlocksType | _allocated_blocks |
|
std::mutex | _mutex |
|
template<typename DerivedType, typename T>
class ska::cheetah::data::CachingAllocatorImplBase< DerivedType, T >
Base class for CachingAllocator implementations.
- Template Parameters
-
DerivedType | { description } |
T | { description } |
Definition at line 41 of file CachingAllocatorImplBase.h.
◆ allocate()
template<typename DerivedType , typename T >
Allocate memory.
- Parameters
-
[in] | num_elements | The number elements to be allocate of type T |
- Returns
- A pointer to the allocated memory
Definition at line 45 of file CachingAllocatorImplBase.cpp.
47 std::lock_guard<std::mutex> lock(_mutex);
51 typename FreeBlocksType::iterator free_block = _free_blocks.find(num_elements);
53 if(free_block != _free_blocks.end())
56 result = free_block->second;
59 _free_blocks.erase(free_block);
69 result = DerivedType::_allocate(num_elements);
71 catch(std::runtime_error &e)
73 throw panda::Error(e);
78 _allocated_blocks.insert(std::make_pair(result, num_elements));
◆ deallocate()
template<typename DerivedType , typename T>
Deallocate memory.
- Parameters
-
[in] | ptr | Pointer to the memory to be deallocated |
[in] | n | The number of elements of type T to be deallocated |
Definition at line 83 of file CachingAllocatorImplBase.cpp.
85 std::lock_guard<std::mutex> lock(_mutex);
87 typename AllocatedBlocksType::iterator iter = _allocated_blocks.find(ptr);
88 std::size_t num_elements = iter->second;
89 _allocated_blocks.erase(iter);
92 _free_blocks.insert(std::make_pair(num_elements, ptr));
The documentation for this class was generated from the following files: