Memory resource implementing the LIFO allocation policies, using an internal arena. More...
#include <cmsis-plus/memory/first-fit-top.h>
Inheritance diagram for os::memory::lifo_inclusive< N >:Public Member Functions | |
Constructors & Destructor | |
| lifo_inclusive (void) | |
| Construct a memory resource object instance. | |
| lifo_inclusive (const char *name) | |
| Construct a named memory resource object instance. | |
| virtual | ~lifo_inclusive () |
| Destruct the memory resource object instance. | |
Public Member Functions | |
| void * | allocate (std::size_t bytes, std::size_t alignment=max_align) |
| Allocate a memory block. | |
| void | deallocate (void *addr, std::size_t bytes, std::size_t alignment=max_align) noexcept |
| Deallocate the previously allocated memory block. | |
| bool | is_equal (memory_resource const &other) const noexcept |
Compare for equality with another memory_resource. | |
| void | reset (void) noexcept |
| Reset the memory manager to the initial state. | |
| bool | coalesce (void) noexcept |
| Coalesce free blocks. | |
| std::size_t | max_size (void) const noexcept |
Get the largest value that can be passed to allocate(). | |
| out_of_memory_handler_t | out_of_memory_handler (out_of_memory_handler_t handler) |
| Set the out of memory handler. | |
| out_of_memory_handler_t | out_of_memory_handler (void) |
| Get the out of memory handler. | |
| std::size_t | total_bytes (void) |
| Get the total size of managed memory. | |
| std::size_t | allocated_bytes (void) |
| Get the current size of all allocated chunks. | |
| std::size_t | max_allocated_bytes (void) |
| Get the maximum allocated size. | |
| std::size_t | free_bytes (void) |
| Get the current size of all free chunks. | |
| std::size_t | allocated_chunks (void) |
| Get the current number of allocated chunks. | |
| std::size_t | free_chunks (void) |
| Get the current number of free chunks. | |
| std::size_t | allocations (void) |
| Get the number of allocations. | |
| std::size_t | deallocations (void) |
| Get the number of deallocations. | |
| void | trace_print_statistics (void) |
| Print a long message with usage statistics. | |
Public Member Functions | |
| const char * | name (void) const |
| Get object name. | |
Static Public Attributes | |
| static const std::size_t | bytes = N |
| Local constant based on template definition. | |
| static constexpr std::size_t | max_align = alignof (std::max_align_t) |
| The largest alignment for the platform. Also default when supplied alignment is not supported. | |
Protected Member Functions | |
Private Member Functions | |
| virtual void * | do_allocate (std::size_t bytes, std::size_t alignment) override |
| Implementation of the memory allocator. | |
Private Member Functions | |
| void | internal_construct_ (void *addr, std::size_t bytes) |
| Internal function to construct the memory resource. | |
| void | internal_reset_ (void) noexcept |
| Internal function to reset the memory resource. | |
| 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. | |
| virtual std::size_t | do_max_size (void) const noexcept override |
| Implementation of the function to get max size. | |
| virtual void | do_reset (void) noexcept override |
| Implementation of the function to reset the memory manager. | |
Private Member Functions | |
| virtual bool | do_is_equal (memory_resource const &other) const noexcept |
| Implementation of the equality comparator. | |
| virtual bool | do_coalesce (void) noexcept |
| Implementation of the function to coalesce free blocks. | |
| void | internal_increase_allocated_statistics (std::size_t bytes) noexcept |
| Update statistics after allocation. | |
| void | internal_decrease_allocated_statistics (std::size_t bytes) noexcept |
| Update statistics after deallocation. | |
This class template is a convenience class that includes an array of chars to be used as the allocation arena.
The common use case it to define statically allocated memory managers.
|
inline |
|
inline |
| [in] | name | Pointer to name. |
Definition at line 387 of file lifo.h.
References os::memory::lifo_inclusive< N >::bytes, os::memory::first_fit_top::internal_construct_(), and os::trace::printf().
|
virtual |
Definition at line 395 of file lifo.h.
References os::trace::printf().
|
inlineinherited |
| bytes | Number of bytes to allocate. |
| alignment | Alignment constraint (power of 2). |
nullptr.Allocate storage with a size of at least bytes bytes. The returned storage is aligned to the specified alignment if such alignment is supported, and to alignof(std::max_align_t) otherwise.
If the storage of the requested size and alignment cannot be obtained:
nullptr;Equivalent to return do_allocate(bytes, alignment);.
bad_alloc() exception.Definition at line 1290 of file os-memory.h.
References os::rtos::memory::memory_resource::do_allocate().
Referenced by os::estd::pmr::polymorphic_allocator< T >::allocate(), calloc(), malloc(), operator new(), and realloc().
|
inlineinherited |
Definition at line 1402 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
inlineinherited |
Definition at line 1420 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
inlineinherited |
Definition at line 1432 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
inlinenoexceptinherited |
| true | if the operation freed more memory. |
| false | if the operation was ineffective. |
In case the memory manager does not coalesce during deallocation, traverse the list of free blocks and coalesce.
Return true if the operation was successful and at least one larger block resulted.
Definition at line 1365 of file os-memory.h.
|
inlinenoexceptinherited |
| addr | Address of the block to free. |
| bytes | Number of bytes to deallocate (may be 0 if unknown). |
| alignment | Alignment constraint (power of 2). |
Deallocate the storage pointed to by addr. The address shall have been returned by a prior call to allocate() on a memory_resource that compares equal to *this, and the storage it points to shall not yet have been deallocated.
Equivalent to return do_deallocate(p, bytes, alignment);.
Definition at line 1312 of file os-memory.h.
Referenced by os::estd::pmr::polymorphic_allocator< T >::deallocate(), free(), and realloc().
|
inlineinherited |
Definition at line 1438 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
overrideprotectedvirtualinherited |
| [in] | bytes | Number of bytes to allocate. |
| [in] | alignment | Alignment constraint (power of 2). |
nullptr.The allocator is deterministic and fast, it always uses the top part of the first block (memory is allocated top-down). If this block is not large enough, the allocation fails; the free list is never traversed, since this is no longer deterministic.
Deallocating in reverse order restores the first block to its original glory. A slight reorder of deallocations is allowed, but memory is not reused until the previous adjacent block is freed, and so on recursively, increasing back the size of the first block.
With the given top-down allocation policy, recent block have always lower addresses.
Similarly, a block is reused only after all more recently allocated blocks are freed.
bad_alloc(). Reimplemented from os::memory::first_fit_top.
Definition at line 68 of file lifo.cpp.
References os::rtos::memory::align_size(), os::memory::first_fit_top::internal_align_(), os::rtos::memory::max(), os::rtos::internal::object_named::name(), and os::trace::printf().
|
protectedvirtualnoexceptinherited |
| true | if the operation resulted in larger blocks. |
| false | if the operation was ineffective. |
The default implementation of this virtual function returns false, meaning the operation was ineffective.
Override this function to perform the action.
Definition at line 468 of file os-memory.cpp.
|
overrideprotectedvirtualnoexceptinherited |
| [in] | addr | Address of a previously allocated block to free. |
| [in] | bytes | Number of bytes to deallocate (may be 0 if unknown). |
| [in] | alignment | Alignment constraint (power of 2). |
Deallocation is not guaranteed to be deterministic, but if done in strict reverse allocation order, it becomes deterministic, otherwise a traversal of the free list is required, the older the block, the more nodes to traverse (the free list is kept in ascending addresses order).
If the block is already in the free list, issue a trace message, but otherwise ignore the condition.
Implements os::rtos::memory::memory_resource.
Definition at line 231 of file first-fit-top.cpp.
References os::trace::printf().
|
protectedvirtualnoexceptinherited |
| other | Reference to another memory_resource. |
| true | The memory_resource objects are equal. |
| false | The memory_resource objects are not equal. |
Compares *this for equality with other. Two memory_resources compare equal if and only if memory allocated from one memory_resource can be deallocated from the other and vice versa.
The most-derived type of other may not match the most derived type of *this. A derived class implementation therefore must typically check whether the most derived types of *this and other match using dynamic_cast, and immediately return false if the cast fails.
Definition at line 419 of file os-memory.cpp.
|
overrideprotectedvirtualnoexceptinherited |
Reimplemented from os::rtos::memory::memory_resource.
Definition at line 410 of file first-fit-top.cpp.
|
overrideprotectedvirtualnoexceptinherited |
Reimplemented from os::rtos::memory::memory_resource.
Definition at line 82 of file first-fit-top.cpp.
References os::trace::printf().
|
inlineinherited |
Definition at line 1414 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
inlineinherited |
Definition at line 1426 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
protectedinherited |
| [in] | chunk | Pointer to chunk. |
| [in] | bytes | Bytes to allocate. |
| [in] | alignment | Power of two. |
Definition at line 416 of file first-fit-top.cpp.
References os::rtos::memory::memory_resource::internal_increase_allocated_statistics().
Referenced by os::memory::first_fit_top::do_allocate(), and os::memory::lifo::do_allocate().
|
protectedinherited |
| [in] | addr | Begin of allocator arena. |
| [in] | bytes | Size of allocator arena, in bytes. |
Definition at line 40 of file first-fit-top.cpp.
References os::memory::first_fit_top::internal_reset_().
Referenced by os::memory::first_fit_top::first_fit_top(), os::memory::first_fit_top_allocated< A >::first_fit_top_allocated(), os::memory::first_fit_top_inclusive< N >::first_fit_top_inclusive(), os::memory::lifo_allocated< A >::lifo_allocated(), and os::memory::lifo_inclusive< N >::lifo_inclusive().
|
protectednoexceptinherited |
| [in] | bytes | Number of deallocated bytes. |
Definition at line 490 of file os-memory.cpp.
|
protectednoexceptinherited |
| [in] | bytes | Number of allocated bytes. |
Definition at line 474 of file os-memory.cpp.
Referenced by os::memory::block_pool::do_allocate(), and os::memory::first_fit_top::internal_align_().
|
protectednoexceptinherited |
Definition at line 62 of file first-fit-top.cpp.
Referenced by os::memory::first_fit_top::internal_construct_().
|
inlinenoexceptinherited |
| other | Reference to another memory_resource. |
| true | The memory_resource objects are equal. |
| false | The memory_resource objects are not equal. |
Compare *this for equality with other. Two memory_resources compare equal if and only if memory allocated from one memory_resource can be deallocated from the other and vice versa.
Definition at line 1331 of file os-memory.h.
|
inlineinherited |
Definition at line 1408 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
inlinenoexceptinherited |
Definition at line 1340 of file os-memory.h.
|
inlineinherited |
All objects return a non-null string; anonymous objects return "-".
Definition at line 753 of file os-decls.h.
Referenced by os::memory::lifo::lifo(), os::memory::malloc_memory_resource::malloc_memory_resource(), os::rtos::message_queue_typed< T, Allocator >::message_queue_typed(), os::memory::block_pool::~block_pool(), os::rtos::event_flags::~event_flags(), os::memory::first_fit_top::~first_fit_top(), os::memory::lifo::~lifo(), os::memory::malloc_memory_resource::~malloc_memory_resource(), os::rtos::memory_pool::~memory_pool(), os::rtos::message_queue::~message_queue(), os::rtos::mutex::~mutex(), os::rtos::semaphore::~semaphore(), os::rtos::thread::~thread(), os::rtos::timer::~timer(), os::rtos::memory_pool::alloc(), os::rtos::thread::cancel(), os::rtos::event_flags::clear(), os::rtos::mutex::consistent(), os::rtos::thread::detach(), os::memory::new_delete_memory_resource::do_allocate(), os::memory::block_pool::do_allocate(), os::memory::first_fit_top::do_allocate(), os::memory::lifo::do_allocate(), os::memory::malloc_memory_resource::do_allocate(), os::rtos::thread::flags_raise(), os::rtos::memory_pool::free(), os::rtos::event_flags::get(), os::rtos::thread::interrupt(), os::rtos::thread::join(), os::rtos::thread::kill(), os::rtos::internal::terminated_threads_list::link(), os::rtos::mutex::lock(), os::rtos::memory::memory_resource::out_of_memory_handler(), os::rtos::semaphore::post(), os::rtos::mutex::prio_ceiling(), os::rtos::mutex::prio_ceiling(), os::rtos::thread::priority(), os::rtos::thread::priority_inherited(), os::rtos::event_flags::raise(), os::rtos::message_queue::receive(), os::rtos::memory_pool::reset(), os::rtos::message_queue::reset(), os::rtos::mutex::reset(), os::rtos::semaphore::reset(), os::rtos::thread::resume(), os::rtos::message_queue::send(), os::rtos::clock::sleep_for(), os::rtos::timer::start(), os::rtos::timer::stop(), os::rtos::memory_pool::timed_alloc(), os::rtos::mutex::timed_lock(), os::rtos::message_queue::timed_receive(), os::rtos::message_queue::timed_send(), os::rtos::semaphore::timed_wait(), os::rtos::event_flags::timed_wait(), os::rtos::memory::memory_resource::trace_print_statistics(), os::rtos::memory_pool::try_alloc(), os::rtos::mutex::try_lock(), os::rtos::message_queue::try_receive(), os::rtos::message_queue::try_send(), os::rtos::event_flags::try_wait(), os::rtos::semaphore::try_wait(), os::rtos::internal::ready_threads_list::unlink_head(), os::rtos::mutex::unlock(), os::rtos::event_flags::wait(), os::rtos::semaphore::wait(), and os::rtos::event_flags::waiting().
|
inlineinherited |
| handler | Pointer to new handler. |
Definition at line 1375 of file os-memory.h.
References os::rtos::internal::object_named::name(), and os::trace::printf().
Referenced by os_startup_initialize_free_store().
|
inlineinherited |
Definition at line 1390 of file os-memory.h.
|
inlinenoexceptinherited |
Definition at line 1349 of file os-memory.h.
|
inlineinherited |
Definition at line 1396 of file os-memory.h.
Referenced by os::rtos::memory::memory_resource::trace_print_statistics().
|
inlineinherited |
Definition at line 1444 of file os-memory.h.
References os::rtos::memory::memory_resource::allocated_bytes(), os::rtos::memory::memory_resource::allocated_chunks(), os::rtos::memory::memory_resource::allocations(), os::rtos::memory::memory_resource::deallocations(), os::rtos::memory::memory_resource::free_bytes(), os::rtos::memory::memory_resource::free_chunks(), os::rtos::memory::memory_resource::max_allocated_bytes(), os::rtos::internal::object_named::name(), os::trace::printf(), and os::rtos::memory::memory_resource::total_bytes().
Referenced by os_terminate_goodbye().
|
static |
Definition at line 176 of file lifo.h.
Referenced by os::memory::lifo_inclusive< N >::lifo_inclusive().
|
staticconstexprinherited |
Definition at line 166 of file os-memory.h.