diff options
Diffstat (limited to 'deimos/core/allocator.h')
-rw-r--r-- | deimos/core/allocator.h | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/deimos/core/allocator.h b/deimos/core/allocator.h index 677501d..e65f316 100644 --- a/deimos/core/allocator.h +++ b/deimos/core/allocator.h @@ -17,15 +17,15 @@ struct IAllocator virtual ~IAllocator() = default;
[[nodiscard]]
- virtual void* Reallocate(
- void* old_ptr, int64_t old_size, int64_t new_size,
+ virtual gsl::owner<void*> Reallocate(
+ gsl::owner<void*> old_ptr, int64_t old_size, int64_t new_size,
MemoryScope scope, const SourceLocation& source_location = {}) = 0;
};
class Allocator
{
- IAllocator* m_allocator;
+ gsl::owner<IAllocator*> m_allocator;
const MemoryScope m_scope;
public:
@@ -37,8 +37,10 @@ public: ~Allocator() = default;
+ constexpr IAllocator* allocator() const { return m_allocator; }
+
[[nodiscard]]
- constexpr void* Allocate(
+ constexpr gsl::owner<void*> Allocate(
int64_t new_size,
const SourceLocation& source_location = {})
{
@@ -46,43 +48,43 @@ public: }
[[nodiscard]]
- void* Reallocate(
- void* old_ptr, int64_t old_size, int64_t new_size,
+ gsl::owner<void*> Reallocate(
+ gsl::owner<void*> old_ptr, int64_t old_size, int64_t new_size,
const SourceLocation& source_location = {})
{
return m_allocator->Reallocate(old_ptr, old_size, new_size, m_scope, source_location);
}
constexpr void Free(
- void* old_ptr, int64_t old_size,
+ gsl::owner<void*> old_ptr, int64_t old_size,
const SourceLocation& source_location = {})
{
(void)m_allocator->Reallocate(old_ptr, old_size, 0, m_scope, source_location);
}
template<typename T, typename... Args>
- T* NewInner(
+ gsl::owner<T*> NewInner(
const SourceLocation& source_location,
Args&&... args)
{
- void* ptr = Allocate(sizeof(T), source_location);
+ gsl::owner<void*> ptr = Allocate(sizeof(T), source_location);
return new(ptr) T(std::forward<Args>(args)...);
}
template<typename T>
- constexpr T* New(const SourceLocation& source_location = {})
+ constexpr gsl::owner<T*> New(const SourceLocation& source_location = {})
{
return NewInner<T>(source_location);
}
template<typename T, typename A0>
- constexpr T* New(A0&& arg0, const SourceLocation& source_location = {})
+ constexpr gsl::owner<T*> New(A0&& arg0, const SourceLocation& source_location = {})
{
return NewInner<T>(source_location, std::forward<A0>(arg0));
}
template<typename T, typename A0, typename A1>
- constexpr T* New(
+ constexpr gsl::owner<T*> New(
A0&& arg0, A1&& arg1,
const SourceLocation& source_location = {})
{
@@ -92,7 +94,7 @@ public: }
template<typename T, typename A0, typename A1, typename A2>
- constexpr T* New(
+ constexpr gsl::owner<T*> New(
A0&& arg0, A1&& arg1, A2&& arg2,
const SourceLocation& source_location = {})
{
@@ -103,7 +105,7 @@ public: }
template<typename T, typename A0, typename A1, typename A2, typename A3>
- constexpr T* New(
+ constexpr gsl::owner<T*> New(
A0&& arg0, A1&& arg1, A2&& arg2, A3&& arg3,
const SourceLocation& source_location = {})
{
@@ -115,7 +117,7 @@ public: }
template<typename T>
- void Delete(T* t, const SourceLocation& source_location = {})
+ void Delete(gsl::owner<T*> t, const SourceLocation& source_location = {})
{
if constexpr (!std::is_trivially_destructible_v<T>)
{
@@ -138,8 +140,8 @@ public: Allocator* system{};
- virtual Allocator* CreateChild(Allocator* parent, gsl::czstring description) = 0;
- virtual void DestroyChild(Allocator*) = 0;
+ virtual gsl::owner<Allocator*> CreateChild(Allocator* parent, gsl::czstring description) = 0;
+ virtual void DestroyChild(gsl::owner<Allocator*>) = 0;
};
} // namespace deimos
|