diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-27 01:16:21 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-04-27 01:16:21 +0200 |
commit | e02f9fd89b059919baf3a8d8bf8b783470976a27 (patch) | |
tree | 6bb16cce1231dba9b0eab5f43ceb7c5d86f8e7cb /deimos/core/allocator.h | |
parent | 08eece258ceff7824250454906bff013a7303c28 (diff) |
Some work on Vulkan initialization
Diffstat (limited to 'deimos/core/allocator.h')
-rw-r--r-- | deimos/core/allocator.h | 21 |
1 files changed, 21 insertions, 0 deletions
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<typename T>
+ gsl::owner<Span<T>> NewArray(int64_t count, const SourceLocation& source_location = {})
+ requires std::is_default_constructible_v<T>
+ {
+ Expects(count > 0);
+
+ auto* raw = Allocate((int64_t)sizeof(T) * count, source_location);
+ if constexpr (std::is_trivially_default_constructible_v<T>)
+ {
+ MemoryZero(raw, (int64_t)sizeof(T) * count);
+ }
+ else
+ {
+ for (int64_t i = 0; i < count; ++i)
+ {
+ new((T*)raw + i) T{};
+ }
+ }
+ return Span<T>{ (T*)raw, count };
+ }
};
class AllocatorApi
|