C++ API memory management definitions. More...
Classes | |
| class | os::rtos::memory::allocator_deleter< A > |
| Allocator deleter. More... | |
| class | os::rtos::memory::allocator_stateless_default_resource< T > |
| Standard allocator based on the RTOS system default memory manager. More... | |
| class | os::rtos::memory::allocator_stateless_polymorphic_synchronized< T, L, get_resource > |
| Allocator using memory resources. More... | |
| class | os::memory::block_pool |
| Memory resource managing a pool of same size blocks, using an existing arena. More... | |
| class | os::memory::block_pool_typed_allocated< T, A > |
| Memory resource managing a dynamically allocated pool. of same size blocks of type T. More... | |
| class | os::memory::block_pool_typed_inclusive< T, N > |
| Memory resource managing an internal pool. of same size blocks of type T. More... | |
| class | os::memory::first_fit_top |
| Memory resource implementing the first fit, top-down allocation policies, using an existing arena. More... | |
| class | os::memory::first_fit_top_allocated< A > |
| Memory resource implementing the first fit, top-down allocation policies, using a dynamically allocated arena. More... | |
| class | os::memory::first_fit_top_inclusive< N > |
| Memory resource implementing the first fit, top-down allocation policies, using an internal arena. More... | |
| class | os::memory::lifo |
| Memory resource implementing the LIFO allocation/deallocation policies, using an existing arena. More... | |
| class | os::memory::lifo_allocated< A > |
| Memory resource implementing the LIFO allocation policies, using a dynamically allocated arena. More... | |
| class | os::memory::lifo_inclusive< N > |
| Memory resource implementing the LIFO allocation policies, using an internal arena. More... | |
| class | os::memory::malloc_memory_resource |
A memory manager that allocates memory via the system std::malloc() and deallocates via std::free(). More... | |
| class | os::rtos::memory::memory_resource |
| Memory resource manager (abstract class). More... | |
| class | os::memory::new_delete_memory_resource |
A memory manager that allocates memory via the system operator new and deallocates via operator delete. More... | |
| class | os::memory::null_memory_resource |
An internal memory manager that throws a bad_alloc() exception when trying to allocate. More... | |
Typedefs | |
| template<typename T > | |
| using | os::rtos::memory::allocator = allocator_stateless_default_resource< T > |
| Type of allocator used by the system objects. Must be stateless. | |
| template<typename T , typename U = T> | |
| using | os::rtos::memory::allocator_typed = allocator_stateless_polymorphic_synchronized< T, scheduler::lockable, get_resource_typed< U > > |
| Type of an allocator for objects of type T. | |
| using | os::rtos::memory::out_of_memory_handler_t = void(*)(void) |
| Type of out of memory handler. | |
| template<typename T , typename U = T> | |
| using | os::rtos::memory::unique_ptr = std::unique_ptr< T, allocator_deleter< allocator_typed< T, U > > > |
| Type of a RTOS unique pointer to objects of type T. | |
Functions | |
| template<typename T , typename A , typename... Args> | |
| auto | os::rtos::memory::allocate_unique (const A &allocator, Args &&... args) |
| Function template to allocate a unique pointer. | |
| template<typename T , typename... Args> | |
| std::enable_if<!std::is_array< T >::value, std::shared_ptr< T > >::type | os::rtos::make_shared (Args &&... args) |
Create an object that is owned by a shared_ptr and is allocated using the RTOS system allocator. | |
| void * | operator new (std::size_t bytes) |
| Allocate space for a new object instance. | |
| template<typename T1 , typename T2 , typename L , F get_resource> | |
| bool | os::rtos::memory::operator!= (const allocator_stateless_polymorphic_synchronized< T1, L, get_resource > &lhs, const allocator_stateless_polymorphic_synchronized< T2, L, get_resource > &rhs) noexcept |
| template<typename T1 , typename T2 , typename L , F get_resource> | |
| bool | os::rtos::memory::operator== (const allocator_stateless_polymorphic_synchronized< T1, L, get_resource > &lhs, const allocator_stateless_polymorphic_synchronized< T2, L, get_resource > &rhs) noexcept |
RTOS System Memory Functions | |
| memory_resource * | os::rtos::memory::malloc_resource (void) noexcept |
Get the address of a memory manager based on POSIX malloc(). | |
| memory_resource * | os::rtos::memory::set_default_resource (memory_resource *res) noexcept |
| Set the default RTOS system memory manager. | |
| memory_resource * | os::rtos::memory::get_default_resource (void) noexcept |
| Get the default RTOS system memory manager. | |
| void | os::rtos::memory::init_once_default_resource (void) |
Operators | |
| bool | os::rtos::memory::operator== (const memory_resource &lhs, const memory_resource &rhs) noexcept |
Compare the memory_resource instances for equality. | |
| bool | os::rtos::memory::operator!= (const memory_resource &lhs, const memory_resource &rhs) noexcept |
Compare the memory_resource instances for inequality. | |
Standard Memory Functions | |
| memory_resource * | os::estd::pmr::new_delete_resource (void) noexcept |
Get the address of a memory manager based on new/delete. | |
| memory_resource * | os::estd::pmr::null_memory_resource (void) noexcept |
| Get the address of an ineffective memory manager. | |
| memory_resource * | os::estd::pmr::set_default_resource (memory_resource *res) noexcept |
| Set the default application memory manager. | |
| memory_resource * | os::estd::pmr::get_default_resource (void) noexcept |
| Get the default application memory manager. | |
The µOS++ RTOS includes several advanced and flexible memory management features.
First, it defines a configurable memory manager for the application free store (also known as the "heap").
Second, it defines a separate memory manager to be used by the RTOS system objects. This separate manager can be configured to use any allocation policy. It may use either a statically or a dynamically allocated area.
The reason for the system memory manager is to allow RTOS system objects to be separated from application objects; this has several advantages:
Third, system objects that require dynamic memory may be created with custom allocators, defined by the user.
Access to the application memory manager is done using the standard functions:
malloc()/free() in C (thread safe)std::malloc()/std::free() in C++ (thread safe)new/delete in C++ (thread safe)The default application memory manager is set in the os_startup_initialize_free_store() function, called by the startup code when running on bare metal.
On synthetic POSIX platforms the default memory manager is os::memory::malloc_memory_resource, which uses memory from the system free store.
By default the RTOS system memory manager is the same as the application memory manager, but, for isolation reasons, it is recommended to define a separate memory manager for the RTOS system objects.
The basic memory management class is os::rtos::memory::memory_resource, which will be standard starting with C++17. The µOS++ version of this class includes several extensions, like out of memory processing and statistics (and this is the reason the class is not defined in os::estd).
| using os::rtos::memory::allocator = typedef allocator_stateless_default_resource<T> |
| T | Type of elements to be allocated. |
Definition at line 53 of file os-types.h.
| using os::rtos::memory::allocator_typed = typedef allocator_stateless_polymorphic_synchronized< T, scheduler::lockable, get_resource_typed<U> > |
| T | type of object. |
The allocator uses scheduler critical sections to be thread safe, and the default memory resource associated with the given type.
Definition at line 1074 of file os-memory.h.
| using os::rtos::memory::out_of_memory_handler_t = typedef void (*) (void) |
Definition at line 141 of file os-memory.h.
| using os::rtos::memory::unique_ptr = typedef std::unique_ptr<T, allocator_deleter<allocator_typed<T, U> >> |
| T | type of object. |
The type is based on the standard unique pointer, but with the specific RTOS deleter.
Definition at line 1086 of file os-memory.h.
| auto os::rtos::memory::allocate_unique | ( | const A & | allocator, |
| Args &&... | args | ||
| ) |
| T | Type of object to be allocated. |
| A | Allocator type. |
| Args | Variable arguments list. |
| allocator | Reference to allocator. |
| args | Arguments used to construct the object of type T. |
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of malloc_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 181 of file memory_resource.
References os::estd::pmr::default_resource.
Referenced by calloc(), free(), malloc(), operator new(), os_terminate_goodbye(), and realloc().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1136 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
Referenced by os_memory_get_default(), and os_terminate_goodbye().
|
noexcept |
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1165 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1180 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1195 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1210 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1225 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1240 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1150 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
|
inlinenoexcept |
If not set explicitly by the user, this function will return an instance of null_memory_resource on bare metal platforms and of malloc_memory_resource on POSIX platforms.
Definition at line 1255 of file os-memory.h.
References os::rtos::memory::init_once_default_resource().
| void os::rtos::memory::init_once_default_resource | ( | void | ) |
Referenced by os::rtos::memory::get_default_resource(), os::rtos::memory::get_resource_typed< condition_variable >(), os::rtos::memory::get_resource_typed< event_flags >(), os::rtos::memory::get_resource_typed< memory_pool >(), os::rtos::memory::get_resource_typed< message_queue >(), os::rtos::memory::get_resource_typed< mutex >(), os::rtos::memory::get_resource_typed< semaphore >(), os::rtos::memory::get_resource_typed< thread >(), and os::rtos::memory::get_resource_typed< timer >().
|
inline |
| args | Arguments for the T object's constructor. |
| * | An exception may be thrown from allocate() or from the constructor of T. |
Definition at line 177 of file os.h.
|
noexcept |
Definition at line 190 of file os-memory.cpp.
|
noexcept |
|
noexcept |
| void * operator new | ( | std::size_t | bytes | ) |
| bytes | Number of bytes to allocate. |
The allocation function (3.7.4.1) called by a new-expression (5.3.4) to allocate a storage of size bytes suitably aligned to represent any object of that size.
Return a non-null pointer to suitably aligned storage (3.7.4), or else throw a bad-alloc exception. This requirement is binding on a replacement version of this function.
Definition at line 136 of file new.cpp.
References os::estd::__throw_bad_alloc(), os::rtos::memory::memory_resource::allocate(), os::estd::pmr::get_default_resource(), os::rtos::interrupts::in_handler_mode(), anonymous_namespace{new.cpp}::new_handler_, and os::trace::printf().
|
noexcept |
|
inlinenoexcept |
| lhs | First instance to compare. |
| rhs | Second instance to compare. |
| true | The two object memory_resource instances are not equal. |
| false | The two object memory_resource instances are equal. |
Definition at line 1470 of file os-memory.h.
|
noexcept |
|
inlinenoexcept |
| lhs | First instance to compare. |
| rhs | Second instance to compare. |
| true | The two object memory_resource instances are equal. |
| false | The two object memory_resource instances are not equal. |
Definition at line 1463 of file os-memory.h.
|
noexcept |
| res | Pointer to new memory manager object instance. |
Definition at line 57 of file memory-resource.cpp.
References os::estd::pmr::default_resource, and os::trace::printf().
Referenced by os_startup_initialize_free_store().
|
noexcept |
| res | Pointer to new memory manager object instance. |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager handling the free RAM.
Definition at line 207 of file os-memory.cpp.
References os::trace::printf().
Referenced by os_startup_initialize_free_store().
|
noexcept |
| res | Pointer to memory resource. |
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 244 of file os-memory.cpp.
References os::trace::printf().
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 262 of file os-memory.cpp.
References os::trace::printf().
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 280 of file os-memory.cpp.
References os::trace::printf().
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 298 of file os-memory.cpp.
References os::trace::printf().
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 316 of file os-memory.cpp.
References os::trace::printf().
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 334 of file os-memory.cpp.
References os::trace::printf().
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 226 of file os-memory.cpp.
References os::trace::printf().
|
noexcept |
On bare metal applications, this function is called from os_startup_initialize_free_store(), during the system startup, with a memory manager specific to this object type.
Definition at line 352 of file os-memory.cpp.
References os::trace::printf().