13#if defined(OS_USE_OS_APP_CONFIG_H)
14#include <cmsis-plus/os-app-config.h>
23#pragma clang diagnostic ignored "-Wc++98-compat"
40#pragma GCC diagnostic push
42#pragma GCC diagnostic ignored "-Wunused-parameter"
71 std::size_t block_padding = calc_block_padding (alignment);
73 alloc_size += block_padding;
74 alloc_size += chunk_offset;
76 std::size_t block_minchunk = calc_block_minchunk (block_padding);
79 chunk_t* chunk =
nullptr;
85 if (free_list_ ==
reinterpret_cast<chunk_t*
> (arena_addr_))
89 int rem =
static_cast<int> (chunk->size - alloc_size);
92 if ((
static_cast<std::size_t
> (rem)) >= block_minchunk)
99 chunk->size =
static_cast<std::size_t
> (rem);
101#pragma GCC diagnostic push
102#pragma GCC diagnostic ignored "-Wcast-align"
105 reinterpret_cast<chunk_t *
> (
reinterpret_cast<char *
> (chunk)
107#pragma GCC diagnostic pop
108 chunk->size = alloc_size;
120 free_list_ = chunk->next;
127 if (chunk !=
nullptr)
132 if (out_of_memory_handler_ ==
nullptr)
134#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
135 trace::printf (
"lifo::%s(%u,%u)=0 @%p %s\n", __func__, bytes,
136 alignment,
this, this->
name ());
142#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
143 trace::printf (
"lifo::%s(%u,%u) @%p %s out of memory\n", __func__,
144 bytes, alignment,
this, this->
name ());
146 out_of_memory_handler_ ();
154#if defined(OS_TRACE_LIBCPP_MEMORY_RESOURCE)
155 trace::printf (
"lifo::%s(%u,%u)=%p,%u @%p %s\n", __func__, bytes,
156 alignment, aligned_payload, alloc_size,
this,
name ());
159 return aligned_payload;
162#pragma GCC diagnostic pop
void * internal_align_(chunk_t *chunk, std::size_t bytes, std::size_t alignment)
Internal function to align a chunk.
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.
constexpr std::size_t align_size(std::size_t size, std::size_t align) noexcept
Helper function to align size values.
constexpr std::size_t max(std::size_t a, std::size_t b)