13#ifndef CMSIS_PLUS_MEMORY_LIFO_H_
14#define CMSIS_PLUS_MEMORY_LIFO_H_
18#if defined(__cplusplus)
26#pragma GCC diagnostic push
28#pragma clang diagnostic ignored "-Wc++98-compat"
86 lifo (
void* addr, std::size_t bytes);
94 lifo (
const char*
name,
void* addr, std::size_t bytes);
120 operator= (
const lifo&) =
delete;
122 operator= (
lifo&&) =
delete;
152 do_allocate (std::size_t bytes, std::size_t alignment)
override;
174 template<std::
size_t N>
261 template<
typename A = os::rtos::memory::allocator<
char>>
283 static_assert(
sizeof(
value_type) ==
sizeof(
typename allocator_traits::value_type),
284 "The allocator must be parametrised with a type of same size.");
376 {
nullptr, addr, bytes }
378 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
383 lifo::lifo (
const char* name,
void* addr, std::size_t bytes) :
385 {
name, addr, bytes }
387 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
393 template<std::
size_t N>
400 template<std::
size_t N>
406 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
408 internal_construct_ (&arena_[0], bytes);
411 template<std::
size_t N>
414 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
433 trace::printf (
"%s(%u) @%p %s\n", __func__, bytes,
this, this->name ());
437 static_cast<allocator_type*
> (&
const_cast<allocator_type&
> (allocator));
439 void* addr = allocator_->allocate (bytes);
445 internal_construct_ (addr, bytes);
451 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
454 if (allocator_ !=
nullptr)
456 allocator_->deallocate (
457 static_cast<typename allocator_traits::pointer
> (arena_addr_),
461 allocator_ =
nullptr;
470#pragma GCC diagnostic pop
Memory resource implementing the first fit, top-down allocation policies, using an existing arena.
Memory resource implementing the LIFO allocation policies, using a dynamically allocated arena.
char value_type
Standard allocator type definition.
std::allocator_traits< A > allocator_traits
Standard allocator traits definition.
lifo_allocated(std::size_t bytes, const allocator_type &allocator=allocator_type())
Construct a memory resource object instance.
virtual ~lifo_allocated()
Destruct the memory resource object instance.
A allocator_type
Standard allocator type definition.
Memory resource implementing the LIFO allocation policies, using an internal arena.
static const std::size_t bytes
Local constant based on template definition.
lifo_inclusive(void)
Construct a memory resource object instance.
virtual ~lifo_inclusive()
Destruct the memory resource object instance.
Memory resource implementing the LIFO allocation/deallocation policies, using an existing arena.
lifo(const char *name)
Construct a named memory resource object instance.
lifo()=default
Default constructor. Construct a memory resource object instance.
virtual ~lifo() override
Destruct the memory resource object instance.
virtual void * do_allocate(std::size_t bytes, std::size_t alignment) override
Implementation of the memory allocator.
const char * name(void) const
Get object name.
int printf(const char *format,...)
Write a formatted string to the trace device.
void __throw_bad_alloc(void)