28#ifndef CMSIS_PLUS_MEMORY_LIFO_H_
29#define CMSIS_PLUS_MEMORY_LIFO_H_
33#if defined(__cplusplus)
41#pragma GCC diagnostic push
44#pragma clang diagnostic ignored "-Wc++98-compat"
102 lifo (
void* addr, std::size_t bytes);
110 lifo (
const char*
name,
void* addr, std::size_t bytes);
136 operator= (
const lifo&) =
delete;
138 operator= (
lifo&&) =
delete;
168 do_allocate (std::size_t bytes, std::size_t alignment)
override;
190 template<std::
size_t N>
277 template<
typename A = os::rtos::memory::allocator<
char>>
299 static_assert(
sizeof(
value_type) ==
sizeof(
typename allocator_traits::value_type),
300 "The allocator must be parametrised with a type of same size.");
392 {
nullptr, addr, bytes }
394 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
399 lifo::lifo (
const char* name,
void* addr, std::size_t bytes) :
401 {
name, addr, bytes }
403 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
409 template<std::
size_t N>
417 template<std::
size_t N>
423 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
425 internal_construct_ (&arena_[0], bytes);
428 template<std::
size_t N>
431 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
451 trace::printf (
"%s(%u) @%p %s\n", __func__, bytes,
this, this->name ());
455 static_cast<allocator_type*
> (&
const_cast<allocator_type&
> (allocator));
457 void* addr = allocator_->allocate (bytes);
463 internal_construct_ (addr, bytes);
469 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
472 if (allocator_ !=
nullptr)
474 allocator_->deallocate (
475 static_cast<typename allocator_traits::pointer
> (arena_addr_),
479 allocator_ =
nullptr;
488#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)