GCC Code Coverage Report


Directory: Fw/Types/
File: MemAllocator.cpp
Date: 2026-09-03 21:15:04
Exec Total Coverage
Lines: 13 32 40.6%
Functions: 5 11 45.5%
Branches: 2 18 11.1%

Line Branch Exec Source
1 /**
2 * \copyright
3 * Copyright 2009-2016, by the California Institute of Technology.
4 * ALL RIGHTS RESERVED. United States Government Sponsorship
5 * acknowledged.
6 */
7 #include <Fw/Types/Assert.hpp>
8 #include <Fw/Types/MemAllocator.hpp>
9 #include <config/MemoryAllocation.hpp>
10 #include <type_traits>
11 namespace Fw {
12
13 9 MemAllocator::MemAllocator() {}
14
15 18 MemAllocator::~MemAllocator() {}
16
17 1 void* MemAllocator::allocate(const FwEnumStoreType identifier, FwSizeType& size, FwSizeType alignment) {
18 1 bool unused = false;
19
1/1
✓ Branch 6 taken 1 times.
2 return this->allocate(identifier, size, unused, alignment);
20 }
21
22 2 void* MemAllocator ::checkedAllocate(const FwEnumStoreType identifier,
23 FwSizeType& size,
24 bool& recoverable,
25 FwSizeType alignment) {
26 2 FwSizeType requestedSize = size;
27 2 void* memory = this->allocate(identifier, size, recoverable, alignment);
28 2 FW_ASSERT(memory != nullptr && size >= requestedSize, static_cast<FwAssertArgType>(identifier),
29 static_cast<FwAssertArgType>(requestedSize), static_cast<FwAssertArgType>(size));
30 2 return memory;
31 }
32
33 1 void* MemAllocator ::checkedAllocate(const FwEnumStoreType identifier, FwSizeType& size, FwSizeType alignment) {
34 1 bool unused = false;
35
1/1
✓ Branch 4 taken 1 times.
2 return this->checkedAllocate(identifier, size, unused, alignment);
36 }
37
38 MemAllocatorRegistry::MemAllocatorRegistry() : m_defaultAllocator(MemAllocatorRegistry::getDefaultAllocator()) {
39 this->registerAllocator(MemoryAllocation::MemoryAllocatorType::SYSTEM, m_defaultAllocator);
40 }
41
42 void MemAllocatorRegistry::registerAllocator(const MemoryAllocation::MemoryAllocatorType type,
43 MemAllocator& allocator) {
44 this->m_allocators[type] = &allocator;
45 }
46
47 MemAllocatorRegistry& MemAllocatorRegistry::getInstance() {
48 static MemAllocatorRegistry registry;
49 return registry;
50 }
51
52 MemAllocator& MemAllocatorRegistry::getAllocator(const MemoryAllocation::MemoryAllocatorType type) {
53 FW_ASSERT(this->m_allocators[type] != nullptr, static_cast<FwAssertArgType>(type));
54 return *this->m_allocators[type];
55 }
56
57 MemAllocator& MemAllocatorRegistry::getAnAllocator(const MemoryAllocation::MemoryAllocatorType type) {
58 // If the allocator is not registered, return the SYSTEM allocator
59 if (this->m_allocators[type] == nullptr) {
60 return this->getAllocator(MemoryAllocation::MemoryAllocatorType::SYSTEM);
61 }
62 return *this->m_allocators[type];
63 }
64
65 MemAllocator& MemAllocatorRegistry::getDefaultAllocator() {
66 static_assert(std::is_constructible<MemoryAllocation::DefaultMemoryAllocatorType>::value,
67 "DefaultMemoryAllocatorType must be constructible without arguments");
68 static MemoryAllocation::DefaultMemoryAllocatorType defaultAllocator;
69 return defaultAllocator;
70 }
71
72 } /* namespace Fw */
73