12#ifndef CMSIS_PLUS_MEMORY_LIFO_H_
13#define CMSIS_PLUS_MEMORY_LIFO_H_
17#if defined(__cplusplus)
25#pragma GCC diagnostic push
27#pragma clang diagnostic ignored "-Wc++98-compat"
84 lifo (
void* addr, std::size_t bytes);
92 lifo (
const char*
name,
void* addr, std::size_t bytes);
116 operator= (
const lifo&)
129 virtual ~lifo ()
override;
148 do_allocate (std::size_t bytes, std::size_t alignment)
override;
169 template <std::
size_t N>
253 template <
typename A = os::rtos::memory::allocator<
char>>
276 ==
sizeof (
typename allocator_traits::value_type),
277 "The allocator must be parametrised with a type of same size.");
368 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
372 inline lifo::lifo (
const char* name,
void* addr, std::size_t bytes)
375 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
381 template <std::
size_t N>
386 template <std::
size_t N>
389 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
394 template <std::
size_t N>
397 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
402 template <
typename A>
409 template <
typename A>
414 trace::printf (
"%s(%u) @%p %s\n", __func__, bytes,
this, this->name ());
420 void* addr = allocator_->allocate (bytes);
429 template <
typename A>
432 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
435 if (allocator_ !=
nullptr)
437 allocator_->deallocate (
438 static_cast<typename allocator_traits::pointer
> (arena_addr_),
442 allocator_ =
nullptr;
451#pragma GCC diagnostic pop
Memory resource implementing the first fit, top-down allocation policies, using an existing arena.
void internal_construct_(void *addr, std::size_t bytes)
Internal function to construct the memory resource.
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)