diff options
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
|