Luna/libluna/include/luna/Alloc.h
apio df77fc8de8
libluna: Remove make_array() and destroy_array()
Placement new on arrays is a bit unreliable and could cause out-of-bounds data accesses.
2023-08-02 14:47:58 +02:00

17 lines
347 B
C++

#pragma once
#include <luna/Heap.h>
#include <luna/PlacementNew.h>
#include <luna/Result.h>
template <typename T, class... Args> [[nodiscard]] Result<T*> make(Args... args)
{
T* const result = (T*)TRY(malloc_impl(sizeof(T)));
new (result) T(args...);
return result;
}
template <typename T> void destroy(T* item)
{
delete item;
}