GCC Code Coverage Report


Directory: ./
File: Fw/Types/MallocAllocator.hpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 2 2 100.0%
Functions: 2 2 100.0%
Branches: 0 0 -%

Line Branch Exec Source
1 /**
2 * \file
3 * \author T. Canham
4 * \brief A MemAllocator implementation class that uses malloc.
5 *
6 * \copyright
7 * Copyright 2009-2016, by the California Institute of Technology.
8 * ALL RIGHTS RESERVED. United States Government Sponsorship
9 * acknowledged.
10 *
11 */
12
13 #ifndef TYPES_MALLOCALLOCATOR_HPP_
14 #define TYPES_MALLOCALLOCATOR_HPP_
15
16 #include <Fw/Types/MemAllocator.hpp>
17
18 namespace Fw {
19
20 //! \brief malloc based memory allocator
21 //!
22 //! This class implements a memory allocator that uses malloc/free to allocate memory and deallocate memory. malloc()
23 //! guarantees alignment for any type and thus does this allocator. It will not respect smaller alignments.
24 //!
25 //! Since this directs to heap space, the identifier is unused and memory is never recoverable.
26 class MallocAllocator : public MemAllocator {
27 public:
28 4 MallocAllocator() = default;
29 8 virtual ~MallocAllocator() = default;
30
31 //! Allocate memory
32 //!
33 //! Allocate memory using malloc(). The identifier is unused and memory is never recoverable.
34 //! malloc() guarantees alignment for any type and so does this allocator. It will not respect smaller alignments.
35 //!
36 //! \param identifier the allocating entity identifier (not used)
37 //! \param size the requested size (not changed)
38 //! \param recoverable - flag to indicate the memory could be recoverable (always set to false)
39 //! \param alignment - alignment requirement for the allocation. Default: maximum alignment defined by C++.
40 //! \return the pointer to memory. Zero if unable to allocate.
41 void* allocate(const FwEnumStoreType identifier,
42 FwSizeType& size,
43 bool& recoverable,
44 FwSizeType alignment = alignof(std::max_align_t)) override;
45 //! Deallocate memory
46 //!
47 //! Deallocate memory previously allocated by allocate() using free(). The identifier is unused but should still
48 //! match the original call.
49 //!
50 //! \param identifier the memory segment identifier (not used)
51 //! \param ptr the pointer to memory returned by allocate()
52 void deallocate(const FwEnumStoreType identifier, void* ptr) override;
53 };
54
55 } /* namespace Fw */
56
57 #endif /* TYPES_MALLOCALLOCATOR_HPP_ */
58