28#ifndef CMSIS_PLUS_MEMORY_FIRST_FIT_TOP_H_
29#define CMSIS_PLUS_MEMORY_FIRST_FIT_TOP_H_
33#if defined(__cplusplus)
41#pragma GCC diagnostic push
44#pragma clang diagnostic ignored "-Wc++98-compat"
45#pragma clang diagnostic ignored "-Wdocumentation-unknown-command"
142#pragma GCC diagnostic push
143#pragma GCC diagnostic ignored "-Wpadded"
147 typedef struct chunk_s
159 struct chunk_s* next;
162#pragma GCC diagnostic pop
199 internal_align_ (chunk_t* chunk, std::size_t bytes, std::size_t alignment);
208 do_allocate (std::size_t bytes, std::size_t alignment)
override;
219 do_deallocate (
void* addr, std::size_t bytes, std::size_t alignment)
252 static constexpr std::size_t chunk_offset = offsetof(chunk_t, next);
253 static constexpr std::size_t chunk_align =
sizeof(
void*);
254 static constexpr std::size_t chunk_minsize =
sizeof(chunk_t);
256 static constexpr std::size_t block_minsize =
sizeof(
void *);
259 static constexpr std::size_t
260 calc_block_padding (std::size_t block_align)
266 static constexpr std::size_t
267 calc_block_minchunk (std::size_t block_padding)
269 return chunk_offset + block_minsize + block_padding;
272 void* arena_addr_ =
nullptr;
275 chunk_t* free_list_ =
nullptr;
297 template<std::
size_t N>
384 template<
typename A = os::rtos::memory::allocator<
char>>
406 static_assert(
sizeof(
value_type) ==
sizeof(
typename allocator_traits::value_type),
407 "The allocator must be parametrised with a type of same size.");
500 rtos::memory::memory_resource
509 {
nullptr, addr, bytes }
517 rtos::memory::memory_resource
520 trace::printf (
"%s(%p,%u) @%p %s\n", __func__, addr, bytes,
this,
523 internal_construct_ (addr, bytes);
528 template<std::
size_t N>
536 template<std::
size_t N>
542 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
544 internal_construct_ (&arena_[0], bytes);
547 template<std::
size_t N>
550 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
566 const char* name, std::size_t bytes,
const allocator_type& allocator) :
570 trace::printf (
"%s(%u) @%p %s\n", __func__, bytes,
this, this->name ());
574 static_cast<allocator_type*
> (&
const_cast<allocator_type&
> (allocator));
576 void* addr = allocator_->allocate (bytes);
582 internal_construct_ (addr, bytes);
588 trace::printf (
"%s() @%p %s\n", __func__,
this, this->name ());
591 if (allocator_ !=
nullptr)
593 allocator_->deallocate (
594 static_cast<typename allocator_traits::pointer
> (arena_addr_),
598 allocator_ =
nullptr;
607#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.