![]() |
F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
|
Memory Allocation base class. More...
#include <Fw/Types/MemAllocator.hpp>
Public Member Functions | |
| virtual void * | allocate (const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t))=0 |
| virtual void | deallocate (const FwEnumStoreType identifier, void *ptr)=0 |
| void * | allocate (const FwEnumStoreType identifier, FwSizeType &size, FwSizeType alignment=alignof(std::max_align_t)) |
| void * | checkedAllocate (const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t)) |
| void * | checkedAllocate (const FwEnumStoreType identifier, FwSizeType &size, FwSizeType alignment=alignof(std::max_align_t)) |
Protected Member Functions | |
| MemAllocator () | |
| virtual | ~MemAllocator () |
Memory Allocation base class.
This class is a pure virtual base class for memory allocators in F Prime. The intent is to provide derived classes that allocate memory from different sources. The base class can be passed to classes so the allocator can be selected at the system level, and different allocators can be used by different components as appropriate.
The identifier can be used to look up a pre-allocated buffer by ID in an embedded system. There is no guarantee that an identifier is unique across multiple calls to allocate(). It is intended to be unique to a given entity.
The size is the requested size of the memory. If the allocator cannot return the requested amount, it should return the actual amount and users should check.
The recoverable flag is intended to be used in embedded environments where memory can survive a processor reset and data can be recovered. The component using the allocator can then use the data. Any integrity checks are up to the user of the memory.
Definition at line 46 of file MemAllocator.hpp.
|
protected |
Definition at line 14 of file MemAllocator.cpp.
|
protectedvirtual |
Definition at line 16 of file MemAllocator.cpp.
|
pure virtual |
Allocate memory
Allows allocation of memory of a given size and alignment. The actual returned memory size may be smaller than the requested size. The alignment of the memory is guaranteed to be at least as large as the requested alignment but may be larger. The recoverable flag indicates if the memory is recoverable (i.e. non-volatile) and thus may be valid without initialization.
identifier is a unique identifier for the allocating entity. This entity (e.g. a component) may call allocate multiple times with the same id, but no other entity in the system shall call allocate with that id.
| identifier | the memory segment identifier, each identifier is to be used in once single allocation |
| size | the requested size - changed to actual if different |
| recoverable | - flag to indicate the memory could be recoverable |
| alignment | - alignment requirement for the allocation. Default: maximum alignment defined by C++. |
Implemented in Fw::MallocAllocator, and Fw::MmapAllocator.
| void * Fw::MemAllocator::allocate | ( | const FwEnumStoreType | identifier, |
| FwSizeType & | size, | ||
| FwSizeType | alignment = alignof(std::max_align_t) |
||
| ) |
Allocate memory without recoverable flag
This is a convenience method that calls allocate() without the recoverable flag. The recoverable flag is filled by the underlying allocator but is not returned to the caller. This is for cases when the caller does not care about recoverability of memory.
| identifier | the memory segment identifier, each identifier is to be used in once single allocation |
| size | the requested size - changed to actual if different |
| alignment | - alignment requirement for the allocation. Default: maximum alignment defined by C++. |
Definition at line 18 of file MemAllocator.cpp.
| void * Fw::MemAllocator::checkedAllocate | ( | const FwEnumStoreType | identifier, |
| FwSizeType & | size, | ||
| bool & | recoverable, | ||
| FwSizeType | alignment = alignof(std::max_align_t) |
||
| ) |
Allocate memory checking that the allocation was successful
This is a convenience method that calls allocate() and checks that the returned pointer is not null and that size is at least as large as the requested size.
Allocations are checked using FW_ASSERT implying that an allocation failure results in a tripped assertion.
| identifier | the memory segment identifier, each identifier is to be used in once single allocation |
| size | the requested size, actual allocation will be at least this size |
| recoverable | - flag to indicate the memory could be recoverable |
| alignment | - alignment requirement for the allocation. Default: maximum alignment defined by C++. |
Definition at line 23 of file MemAllocator.cpp.
| void * Fw::MemAllocator::checkedAllocate | ( | const FwEnumStoreType | identifier, |
| FwSizeType & | size, | ||
| FwSizeType | alignment = alignof(std::max_align_t) |
||
| ) |
Allocate memory checking that the allocation was successful without recoverable flag
This is a convenience method that calls allocate() and checks that the returned pointer is not null and that size is at least as large as the requested size. The recoverable flag is filled by the underlying allocator but is not returned to the caller. This is for cases when the caller does not care about recoverability of memory.
Allocations are checked using FW_ASSERT implying that an allocation failure results in a tripped assertion.
| identifier | the memory segment identifier, each identifier is to be used in once single allocation |
| size | the requested size, actual allocation will be at least this size |
| alignment | - alignment requirement for the allocation. Default: maximum alignment defined by C++. |
Definition at line 34 of file MemAllocator.cpp.
|
pure virtual |
Deallocate memory
Deallocate memory previously allocated by allocate(). The pointer must be one returned by allocate() and the identifier must match the one used in the original allocate() call.
| identifier | the memory segment identifier, each identifier is to be used in once single allocation |
| ptr | the pointer to memory returned by allocate() |
Implemented in Fw::MallocAllocator, and Fw::MmapAllocator.