| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /** | ||
| 2 | * \author T. Canham | ||
| 3 | * \brief Implementation of malloc based allocator | ||
| 4 | * | ||
| 5 | * \copyright | ||
| 6 | * Copyright 2009-2016, by the California Institute of Technology. | ||
| 7 | * ALL RIGHTS RESERVED. United States Government Sponsorship | ||
| 8 | * acknowledged. | ||
| 9 | */ | ||
| 10 | #include <Fw/Types/Assert.hpp> | ||
| 11 | #include <Fw/Types/MallocAllocator.hpp> | ||
| 12 | #include <cstdlib> | ||
| 13 | |||
| 14 | namespace Fw { | ||
| 15 | |||
| 16 | 4 | void* MallocAllocator::allocate(const FwEnumStoreType identifier, | |
| 17 | FwSizeType& size, | ||
| 18 | bool& recoverable, | ||
| 19 | FwSizeType alignment) { | ||
| 20 | // don't use identifier | ||
| 21 | // heap memory is never recoverable | ||
| 22 | 4 | recoverable = false; | |
| 23 | 4 | FW_ASSERT(size < std::numeric_limits<size_t>::max()); | |
| 24 | 4 | void* mem = ::malloc(static_cast<size_t>(size)); | |
| 25 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (nullptr == mem) { |
| 26 | ✗ | size = 0; // set to zero if can't get memory | |
| 27 | } | ||
| 28 | 4 | return mem; | |
| 29 | } | ||
| 30 | |||
| 31 | 4 | void MallocAllocator::deallocate(const FwEnumStoreType identifier, void* ptr) { | |
| 32 | 4 | ::free(ptr); | |
| 33 | 4 | } | |
| 34 | } /* namespace Fw */ | ||
| 35 |