13#ifndef CMSIS_PLUS_MEMORY_FIRST_FIT_TOP_H_
14#define CMSIS_PLUS_MEMORY_FIRST_FIT_TOP_H_
18#if defined(__cplusplus)
26#pragma GCC diagnostic push
28#pragma clang diagnostic ignored "-Wc++98-compat"
29#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
126#pragma GCC diagnostic push
127#if defined(__clang__)
128#pragma clang diagnostic ignored "-Wpadded"
129#elif defined(__GNUC__)
130#pragma GCC diagnostic ignored "-Wpadded"
135 typedef struct chunk_s
150#pragma GCC diagnostic pop
187 internal_align_ (chunk_t* chunk, std::size_t bytes, std::size_t alignment);
196 do_allocate (std::size_t bytes, std::size_t alignment)
override;
207 do_deallocate (
void* addr, std::size_t bytes, std::size_t alignment)
240 static constexpr std::size_t chunk_offset = offsetof(chunk_t, next);
241 static constexpr std::size_t chunk_align =
sizeof(
void*);
242 static constexpr std::size_t chunk_minsize =
sizeof(chunk_t);
244 static constexpr std::size_t block_minsize =
sizeof(
void *);
247 static constexpr std::size_t
248 calc_block_padding (std::size_t block_align)
254 static constexpr std::size_t
255 calc_block_minchunk (std::size_t block_padding)
257 return chunk_offset + block_minsize + block_padding;
260 void* arena_addr_ =
nullptr;
263 chunk_t* free_list_ =
nullptr;
285 template<std::
size_t N>
372 template<
typename A = os::rtos::memory::allocator<
char>>
394 static_assert(
sizeof(
value_type) ==
sizeof(
typename allocator_traits::value_type),
395 "The allocator must be parametrised with a type of same size.");
488 rtos::memory::memory_resource
496 {
nullptr, addr, bytes }
503 rtos::memory::memory_resource
506 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
509 internal_construct_ (addr, bytes);
514 template<std::
size_t N>
521 template<std::
size_t N>
527 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
529 internal_construct_ (&arena_[0], bytes);
532 template<std::
size_t N>
535 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
550 const char* name, std::size_t bytes,
const allocator_type& allocator) :
554 trace::printf (
"%s(%u) @%p %s\n", __func__, bytes,
this, this->name ());
558 static_cast<allocator_type*
> (&
const_cast<allocator_type&
> (allocator));
560 void* addr = allocator_->allocate (bytes);
566 internal_construct_ (addr, bytes);
572 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
575 if (allocator_ !=
nullptr)
577 allocator_->deallocate (
578 static_cast<typename allocator_traits::pointer
> (arena_addr_),
582 allocator_ =
nullptr;
591#pragma GCC diagnostic pop
Memory resource implementing the first fit, top-down allocation policies, using a dynamically allocat...
first_fit_top_allocated(std::size_t bytes, const allocator_type &allocator=allocator_type())
Construct a memory resource object instance.
A allocator_type
Standard allocator type definition.
std::allocator_traits< A > allocator_traits
Standard allocator traits definition.
virtual ~first_fit_top_allocated()
Destruct the memory resource object instance.
char value_type
Standard allocator type definition.
Memory resource implementing the first fit, top-down allocation policies, using an internal arena.
virtual ~first_fit_top_inclusive()
Destruct the memory resource object instance.
first_fit_top_inclusive(void)
Construct a memory resource object instance.
static const std::size_t bytes
Local constant based on template definition.
Memory resource implementing the first fit, top-down allocation policies, using an existing arena.
first_fit_top()=default
Default constructor. Construct a memory resource object instance.
virtual ~first_fit_top() override
Destruct the memory resource object instance.
virtual void do_reset(void) noexcept override
Implementation of the function to reset the memory manager.
void * internal_align_(chunk_t *chunk, std::size_t bytes, std::size_t alignment)
Internal function to align a chunk.
virtual void do_deallocate(void *addr, std::size_t bytes, std::size_t alignment) noexcept override
Implementation of the memory deallocator.
void internal_reset_(void) noexcept
Internal function to reset the memory resource.
virtual void * do_allocate(std::size_t bytes, std::size_t alignment) override
Implementation of the memory allocator.
virtual std::size_t do_max_size(void) const noexcept override
Implementation of the function to get max size.
void internal_construct_(void *addr, std::size_t bytes)
Internal function to construct the memory resource.
const char * name(void) const
Get object name.
Memory resource manager (abstract class).
int printf(const char *format,...)
Write a formatted string to the trace device.
void __throw_bad_alloc(void)
constexpr std::size_t max(std::size_t a, std::size_t b)
Single file µOS++ RTOS definitions.