F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
MallocAllocator.cpp
Go to the documentation of this file.
1 
10 #include <Fw/Types/Assert.hpp>
12 #include <cstdlib>
13 
14 namespace Fw {
15 
17  FwSizeType& size,
18  bool& recoverable,
19  FwSizeType alignment) {
20  // don't use identifier
21  // heap memory is never recoverable
22  recoverable = false;
23  FW_ASSERT(size < std::numeric_limits<size_t>::max());
24  void* mem = ::malloc(static_cast<size_t>(size));
25  if (nullptr == mem) {
26  size = 0; // set to zero if can't get memory
27  }
28  return mem;
29 }
30 
31 void MallocAllocator::deallocate(const FwEnumStoreType identifier, void* ptr) {
32  ::free(ptr);
33 }
34 } /* namespace Fw */
void * allocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t)) override
PlatformSizeType FwSizeType
I32 FwEnumStoreType
void deallocate(const FwEnumStoreType identifier, void *ptr) override
A MemAllocator implementation class that uses malloc.
Implementation of malloc based allocator.
#define FW_ASSERT(...)
Definition: Assert.hpp:14