12#ifndef CMSIS_PLUS_MEMORY_FIRST_FIT_TOP_H_
13#define CMSIS_PLUS_MEMORY_FIRST_FIT_TOP_H_
17#if defined(__cplusplus)
25#pragma GCC diagnostic push
27#pragma clang diagnostic ignored "-Wc++98-compat"
28#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
122#pragma GCC diagnostic push
123#if defined(__clang__)
124#pragma clang diagnostic ignored "-Wpadded"
125#elif defined(__GNUC__)
126#pragma GCC diagnostic ignored "-Wpadded"
131 typedef struct chunk_s
146#pragma GCC diagnostic pop
184 std::size_t alignment);
193 do_allocate (std::size_t bytes, std::size_t alignment)
override;
205 std::size_t alignment)
noexcept override;
236 static constexpr std::size_t chunk_offset = offsetof (chunk_t, next);
237 static constexpr std::size_t chunk_align =
sizeof (
void*);
238 static constexpr std::size_t chunk_minsize =
sizeof (chunk_t);
240 static constexpr std::size_t block_minsize =
sizeof (
void*);
243 static constexpr std::size_t
244 calc_block_padding (std::size_t block_align)
250 static constexpr std::size_t
251 calc_block_minchunk (std::size_t block_padding)
253 return chunk_offset + block_minsize + block_padding;
256 void* arena_addr_ =
nullptr;
259 chunk_t* free_list_ =
nullptr;
280 template <std::
size_t N>
364 template <
typename A = os::rtos::memory::allocator<
char>>
387 ==
sizeof (
typename allocator_traits::value_type),
388 "The allocator must be parametrised with a type of same size.");
479 : rtos::memory::memory_resource{ name }
490 : rtos::memory::memory_resource{ name }
492 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
500 template <std::
size_t N>
506 template <std::
size_t N>
511 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
516 template <std::
size_t N>
519 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
524 template <
typename A>
531 template <
typename A>
533 const char* name, std::size_t bytes,
const allocator_type& allocator)
536 trace::printf (
"%s(%u) @%p %s\n", __func__, bytes,
this, this->name ());
542 void* addr = allocator_->allocate (bytes);
551 template <
typename A>
554 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
557 if (allocator_ !=
nullptr)
559 allocator_->deallocate (
560 static_cast<typename allocator_traits::pointer
> (arena_addr_),
564 allocator_ =
nullptr;
573#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.