diff --git a/BAN/include/BAN/Memory.h b/BAN/include/BAN/Memory.h new file mode 100644 index 000000000..367dcf9b8 --- /dev/null +++ b/BAN/include/BAN/Memory.h @@ -0,0 +1,18 @@ +#pragma once + +#if defined(__is_kernel) + #include +#else + #include +#endif + +namespace BAN +{ + #if defined(__is_kernel) + static constexpr auto& allocator = kmalloc; + static constexpr auto& deallocator = kfree; + #else + static constexpr auto& allocator = malloc; + static constexpr auto& deallocator = free; + #endif +} \ No newline at end of file diff --git a/BAN/include/BAN/Queue.h b/BAN/include/BAN/Queue.h index 9b469a0e0..7ba4063a8 100644 --- a/BAN/include/BAN/Queue.h +++ b/BAN/include/BAN/Queue.h @@ -1,12 +1,7 @@ #pragma once #include - -#if defined(__is_kernel) - #include -#else - #include -#endif +#include #include #include @@ -19,16 +14,6 @@ namespace BAN template class Queue { - private: - #if defined(__is_kernel) - static constexpr auto& allocator = kmalloc; - static constexpr auto& deallocator = kfree; - #else - static constexpr auto& allocator = malloc; - static constexpr auto& deallocator = free; - #endif - - public: using size_type = uint32_t; using value_type = T; @@ -58,7 +43,9 @@ namespace BAN template Queue::~Queue() { - Queue::deallocator(m_data); + for (size_type i = 0; i < m_size; i++) + m_data[i].~T(); + BAN::deallocator(m_data); } template @@ -110,12 +97,12 @@ namespace BAN return {}; size_type new_cap = MAX(m_capacity * 1.5f, m_capacity + 1); - void* new_data = Queue::allocator(new_cap * sizeof(T)); + void* new_data = BAN::allocator(new_cap * sizeof(T)); if (new_data == nullptr) - return Error::FromString("Queue: out of memory"); + return Error::FromString("Queue: Could not allocate memory"); memcpy(new_data, m_data, m_size * sizeof(T)); - Queue::deallocator(m_data); + BAN::deallocator(m_data); m_data = (T*)new_data; m_capacity = new_cap;