zpp
Zephyr C++20 Framework
zpp::base_heap< T_Heap > Class Template Reference

Heap memory allocater CRTP base class. More...

#include <heap.hpp>

Public Types

using native_type = struct k_heap
 
using native_pointer = native_type *
 
using native_const_pointer = native_type const *
 

Public Member Functions

void * allocate (size_t bytes) noexcept
 Allocate memory from this heap wainting forever. More...
 
void * allocate (size_t bytes, size_t align) noexcept
 Allocate memory from this heap waiting forever. More...
 
void * try_allocate (size_t bytes) noexcept
 Allocate memory from this heap without waiting. More...
 
void * try_allocate (size_t bytes, size_t align) noexcept
 Allocate memory from this heap without waiting. More...
 
template<class T_Rep , class T_Period >
void * try_allocate_for (size_t bytes, const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
 Allocate memory from this heap waiting with a timeout. More...
 
template<class T_Rep , class T_Period >
void * try_allocate_for (size_t bytes, size_t align, const std::chrono::duration< T_Rep, T_Period > &timeout) noexcept
 Allocate memory from this heap waiting with a timeout. More...
 
void deallocate (void *mem) noexcept
 Deallocate memory previously allocated. More...
 
auto native_handle () noexcept -> native_pointer
 get the native zephyr heap handle. More...
 
auto native_handle () const noexcept -> native_const_pointer
 get the native zephyr heap handle. More...
 
 base_heap (const base_heap &)=delete
 
 base_heap (base_heap &&)=delete
 
base_heapoperator= (const base_heap &)=delete
 
base_heapoperator= (base_heap &&)=delete
 

Protected Member Functions

constexpr base_heap () noexcept
 default protected constructor so only derived objects can be created More...
 

Detailed Description

template<class T_Heap>
class zpp::base_heap< T_Heap >

Heap memory allocater CRTP base class.

Definition at line 23 of file heap.hpp.

Member Typedef Documentation

◆ native_const_pointer

template<class T_Heap >
using zpp::base_heap< T_Heap >::native_const_pointer = native_type const *

Definition at line 27 of file heap.hpp.

◆ native_pointer

template<class T_Heap >
using zpp::base_heap< T_Heap >::native_pointer = native_type*

Definition at line 26 of file heap.hpp.

◆ native_type

template<class T_Heap >
using zpp::base_heap< T_Heap >::native_type = struct k_heap

Definition at line 25 of file heap.hpp.

Constructor & Destructor Documentation

◆ base_heap() [1/3]

template<class T_Heap >
constexpr zpp::base_heap< T_Heap >::base_heap ( )
inlineconstexprprotectednoexcept

default protected constructor so only derived objects can be created

Definition at line 32 of file heap.hpp.

32 { }

◆ base_heap() [2/3]

template<class T_Heap >
zpp::base_heap< T_Heap >::base_heap ( const base_heap< T_Heap > &  )
delete

◆ base_heap() [3/3]

template<class T_Heap >
zpp::base_heap< T_Heap >::base_heap ( base_heap< T_Heap > &&  )
delete

Member Function Documentation

◆ allocate() [1/2]

template<class T_Heap >
void* zpp::base_heap< T_Heap >::allocate ( size_t  bytes)
inlinenoexcept

Allocate memory from this heap wainting forever.

Parameters
bytesthe number of bytes to allocate
Returns
The memory or nullptr on failure

Definition at line 42 of file heap.hpp.

43  {
44  return k_heap_alloc(native_handle(), bytes, K_FOREVER);
45  }
auto native_handle() noexcept -> native_pointer
get the native zephyr heap handle.
Definition: heap.hpp:134

References zpp::base_heap< T_Heap >::native_handle().

◆ allocate() [2/2]

template<class T_Heap >
void* zpp::base_heap< T_Heap >::allocate ( size_t  bytes,
size_t  align 
)
inlinenoexcept

Allocate memory from this heap waiting forever.

Parameters
bytesthe number of bytes to allocate
alignthe alignment of the allocated memory
Returns
The memory or nullptr on failure

Definition at line 56 of file heap.hpp.

57  {
58  return k_heap_aligned_alloc(native_handle(), align, bytes, K_FOREVER);
59  }

References zpp::base_heap< T_Heap >::native_handle().

◆ deallocate()

template<class T_Heap >
void zpp::base_heap< T_Heap >::deallocate ( void *  mem)
inlinenoexcept

Deallocate memory previously allocated.

Parameters
memthe memory to deallocate

Definition at line 124 of file heap.hpp.

125  {
126  k_heap_free(native_handle(), mem);
127  }

References zpp::base_heap< T_Heap >::native_handle().

◆ native_handle() [1/2]

template<class T_Heap >
auto zpp::base_heap< T_Heap >::native_handle ( ) const -> native_const_pointer
inlinenoexcept

get the native zephyr heap handle.

Returns
A pointer to the zephyr k_heap.

Definition at line 144 of file heap.hpp.

145  {
146  return static_cast<const T_Heap*>(this)->native_handle();
147  }

References zpp::base_heap< T_Heap >::native_handle().

◆ native_handle() [2/2]

template<class T_Heap >
auto zpp::base_heap< T_Heap >::native_handle ( ) -> native_pointer
inlinenoexcept

get the native zephyr heap handle.

Returns
A pointer to the zephyr k_heap.

Definition at line 134 of file heap.hpp.

135  {
136  return static_cast<T_Heap*>(this)->native_handle();
137  }

Referenced by zpp::base_heap< T_Heap >::allocate(), zpp::base_heap< T_Heap >::deallocate(), zpp::base_heap< T_Heap >::native_handle(), zpp::base_heap< T_Heap >::try_allocate(), and zpp::base_heap< T_Heap >::try_allocate_for().

◆ operator=() [1/2]

template<class T_Heap >
base_heap& zpp::base_heap< T_Heap >::operator= ( base_heap< T_Heap > &&  )
delete

◆ operator=() [2/2]

template<class T_Heap >
base_heap& zpp::base_heap< T_Heap >::operator= ( const base_heap< T_Heap > &  )
delete

◆ try_allocate() [1/2]

template<class T_Heap >
void* zpp::base_heap< T_Heap >::try_allocate ( size_t  bytes)
inlinenoexcept

Allocate memory from this heap without waiting.

Parameters
bytesthe number of bytes to allocate
Returns
The memory or nullptr on failure

Definition at line 69 of file heap.hpp.

70  {
71  return k_heap_alloc(native_handle(), bytes, K_NO_WAIT);
72  }

References zpp::base_heap< T_Heap >::native_handle().

Referenced by zpp::thread::thread().

◆ try_allocate() [2/2]

template<class T_Heap >
void* zpp::base_heap< T_Heap >::try_allocate ( size_t  bytes,
size_t  align 
)
inlinenoexcept

Allocate memory from this heap without waiting.

Parameters
bytesthe number of bytes to allocate
alignthe alignment of the allocated memory
Returns
The memory or nullptr on failure

Definition at line 83 of file heap.hpp.

84  {
85  return k_heap_aligned_alloc(native_handle(), align, bytes, K_NO_WAIT);
86  }

References zpp::base_heap< T_Heap >::native_handle().

◆ try_allocate_for() [1/2]

template<class T_Heap >
template<class T_Rep , class T_Period >
void* zpp::base_heap< T_Heap >::try_allocate_for ( size_t  bytes,
const std::chrono::duration< T_Rep, T_Period > &  timeout 
)
inlinenoexcept

Allocate memory from this heap waiting with a timeout.

Parameters
bytesthe number of bytes to allocate
timeoutthe time to try the allocation
Returns
The memory or nullptr on failure

Definition at line 98 of file heap.hpp.

99  {
100  return k_heap_alloc(native_handle(), bytes, to_timeout(timeout));
101  }
constexpr k_timeout_t to_timeout(const std::chrono::duration< T_Rep, T_Period > &d) noexcept
convert a duration to tick
Definition: clock.hpp:88

References zpp::base_heap< T_Heap >::native_handle(), and zpp::to_timeout().

◆ try_allocate_for() [2/2]

template<class T_Heap >
template<class T_Rep , class T_Period >
void* zpp::base_heap< T_Heap >::try_allocate_for ( size_t  bytes,
size_t  align,
const std::chrono::duration< T_Rep, T_Period > &  timeout 
)
inlinenoexcept

Allocate memory from this heap waiting with a timeout.

Parameters
bytesthe number of bytes to allocate
alignthe alignment of the allocated memory
timeoutthe time to try the allocation
Returns
The memory or nullptr on failure

Definition at line 114 of file heap.hpp.

115  {
116  return k_heap_aligned_alloc(native_handle(), align, bytes, to_timeout(timeout));
117  }

References zpp::base_heap< T_Heap >::native_handle(), and zpp::to_timeout().


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