Skip to content

Commit 12b07c4

Browse files
committed
Added destructor to TlsfAllocator
1 parent 288a097 commit 12b07c4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

engine/utils/allocators/Tlsf.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,23 @@ TlsfAllocator<T>::TlsfAllocator(const T size)
7575
AddNewBlock(paddedSize, TO_HEADER(data));
7676
}
7777

78+
template<typename T>
79+
TlsfAllocator<T>::~TlsfAllocator()
80+
{
81+
if (data) free(data);
82+
83+
totalBytesRemaining = 0;
84+
capacity = 0;
85+
bytesRemaining = 0;
86+
totalSize = 0;
87+
88+
flBitmask = 0;
89+
90+
data = nullptr;
91+
freeList = nullptr;
92+
slBitmasks = nullptr;
93+
}
94+
7895
template<typename T>
7996
void TlsfAllocator<T>::CreateHeader(uint8_t* ptr, const T size, HeaderFlags flags)
8097
{

engine/utils/allocators/Tlsf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,19 @@ class TlsfAllocator
7070
* @brief Empty constructor Initialises the constructor and size to 0 (null)
7171
*/
7272
TlsfAllocator();
73+
7374
/**
7475
* @brief Size initialiser. Accepts a number representing the number of bytes to allocate to
7576
* the allocator's memory buffer
7677
* @param size the number of bytes to allocate, cannot be less than 16
7778
*/
7879
TlsfAllocator(const T size);
7980

81+
/**
82+
* @brief Destructor, deallocates all memory and sets all values to zero
83+
*/
84+
~TlsfAllocator();
85+
8086
// Deleted copy and move constructors
8187

8288
TlsfAllocator(const TlsfAllocator& other) = delete;

0 commit comments

Comments
 (0)