From e02f9fd89b059919baf3a8d8bf8b783470976a27 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Sat, 27 Apr 2024 01:16:21 +0200 Subject: Some work on Vulkan initialization --- deimos/core/allocator.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'deimos/core/allocator.h') diff --git a/deimos/core/allocator.h b/deimos/core/allocator.h index 26374bd..5afb824 100644 --- a/deimos/core/allocator.h +++ b/deimos/core/allocator.h @@ -125,6 +125,27 @@ public: } Free(t, sizeof(T), source_location); } + + template + gsl::owner> NewArray(int64_t count, const SourceLocation& source_location = {}) + requires std::is_default_constructible_v + { + Expects(count > 0); + + auto* raw = Allocate((int64_t)sizeof(T) * count, source_location); + if constexpr (std::is_trivially_default_constructible_v) + { + MemoryZero(raw, (int64_t)sizeof(T) * count); + } + else + { + for (int64_t i = 0; i < count; ++i) + { + new((T*)raw + i) T{}; + } + } + return Span{ (T*)raw, count }; + } }; class AllocatorApi -- cgit