[*] Creasing allocators
This commit is contained in:
parent
d549c3aeef
commit
947356120b
@ -32,6 +32,18 @@ namespace Aurora::Memory
|
||||
AUKN_SYM AuUInt GetChunkSize(const void *head);
|
||||
AUKN_SYM AuUInt GetPageSize();
|
||||
|
||||
|
||||
static void *__FAlloc(Types::size_t length, Types::size_t align)
|
||||
{
|
||||
return _FAlloc(length, align);
|
||||
}
|
||||
|
||||
static void __Free(void *buffer)
|
||||
{
|
||||
_Free(buffer);
|
||||
}
|
||||
|
||||
|
||||
// These memory management APIs do not support class types, and will likely *never* support them
|
||||
// QST already handles dynamic allocation of structs in a given heap properly (afaik)
|
||||
// _new, new, et al are backed by operator overloads directed towards these functions
|
||||
@ -78,32 +90,6 @@ namespace Aurora::Memory
|
||||
});
|
||||
}
|
||||
|
||||
template <class T>
|
||||
struct SpeedyArrayAllocator
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
SpeedyArrayAllocator() = default;
|
||||
template <class U> constexpr SpeedyArrayAllocator(const SpeedyArrayAllocator <U> &) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
[[nodiscard]] T *allocate(Types::size_t n)
|
||||
{
|
||||
if (auto p = (NewArray<T>(n)))
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
void deallocate(T *p, Types::size_t n) noexcept
|
||||
{
|
||||
_Free(p);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
T FAlloc(Types::size_t length)
|
||||
{
|
||||
|
@ -27,7 +27,7 @@ namespace Aurora::Memory::Transition
|
||||
|
||||
AUKN_SHARED_API(MemoryTransactor, EXTransitionOperation);
|
||||
|
||||
AUKN_SYM bool ReservePhysicalMemory(const AuSPtr<EXTransitionOperation> &operation, AuUInt length);
|
||||
AUKN_SYM bool CommitToPhysical(const AuSPtr<EXTransitionOperation> &operation);
|
||||
AUKN_SYM bool ReserveMemory(const AuSPtr<EXTransitionOperation> &operation, AuUInt length, bool prefetch = true);
|
||||
AUKN_SYM bool CommitToExecutable(const AuSPtr<EXTransitionOperation> &operation);
|
||||
AUKN_SYM void Free(const AuSPtr<EXTransitionOperation> &operation);
|
||||
}
|
@ -7,11 +7,15 @@
|
||||
***/
|
||||
#pragma once
|
||||
|
||||
|
||||
#if !defined(AUROXTL_NO_TRY)
|
||||
#define AUROXTL_COMMODITY_TRY try
|
||||
#define AUROXTL_COMMODITY_CATCH catch (...)
|
||||
#else
|
||||
#define AUROXTL_COMMODITY_TRY
|
||||
#define AUROXTL_COMMODITY_CATCH while (0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Crossing API boundaries will resort in an alloc + copy
|
||||
// Don't enable unless you're in the ecosystem
|
||||
// Default behaviour (omitted): use the exact std::string type
|
||||
//#define AURORA_ROXTL_STRING_USE_STR_ALLOCATOR
|
@ -11,6 +11,8 @@
|
||||
#define AURORA_RUNTIME_AU_LIST std::vector
|
||||
#endif
|
||||
|
||||
#include "auMemoryModel.hpp"
|
||||
|
||||
#if defined(_CPPSHARP) || defined(_AURORA_NO_SPECIAL_ARRAY_OPTIMIAZATION) || (!defined(_AUHAS_AURORARUNTIME) && !defined(AURORA_ENGINE_KERNEL))
|
||||
|
||||
template <class T>
|
||||
@ -18,13 +20,14 @@ using AuList = AURORA_RUNTIME_AU_LIST<T>;
|
||||
|
||||
#else
|
||||
|
||||
namespace Aurora::Memory
|
||||
{
|
||||
template <class T>
|
||||
struct SpeedyArrayAllocator;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
using AuList = AuConditional_t<AuIsClass_v<T>, AURORA_RUNTIME_AU_LIST<T>, AURORA_RUNTIME_AU_LIST<T, Aurora::Memory::SpeedyArrayAllocator<T>>>;
|
||||
using AuList = AURORA_RUNTIME_AU_LIST<T,
|
||||
AuConditional_t<AuIsClass_v<T>,
|
||||
Aurora::Memory::ClassArrayAllocator<T>,
|
||||
Aurora::Memory::PrimitiveArrayAllocator<T>
|
||||
>
|
||||
>;
|
||||
|
||||
#endif
|
@ -152,4 +152,56 @@ static void auline AuSafeDelete(T *in)
|
||||
delete static_cast<Z>(in);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace Aurora::Memory
|
||||
{
|
||||
|
||||
static void *__FAlloc(Types::size_t length, Types::size_t align);
|
||||
static void __Free(void *buffer);
|
||||
|
||||
template <class T>
|
||||
struct BaseAuroraRuntimeAllocator
|
||||
{
|
||||
typedef T value_type;
|
||||
|
||||
AU_COPY_MOVE(BaseAuroraRuntimeAllocator)
|
||||
|
||||
constexpr BaseAuroraRuntimeAllocator()
|
||||
{}
|
||||
|
||||
template <class U> constexpr BaseAuroraRuntimeAllocator(const BaseAuroraRuntimeAllocator <U> &) noexcept
|
||||
{
|
||||
}
|
||||
|
||||
inline [[nodiscard]] constexpr T* allocate(Types::size_t n)
|
||||
{
|
||||
if (auto p = (__FAlloc(n * sizeof(T), alignof(T))))
|
||||
{
|
||||
return AuReinterpretCast<T*>(p);
|
||||
}
|
||||
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
inline constexpr void deallocate(T *p, std::size_t n) noexcept
|
||||
{
|
||||
__Free(p);
|
||||
}
|
||||
|
||||
inline bool operator==(const BaseAuroraRuntimeAllocator &op)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
using PrimitiveArrayAllocator = BaseAuroraRuntimeAllocator<T>;
|
||||
|
||||
template<typename T>
|
||||
using ClassArrayAllocator = BaseAuroraRuntimeAllocator<T>;
|
||||
|
||||
template<typename T>
|
||||
using StringAllocator = BaseAuroraRuntimeAllocator<T>;
|
||||
|
||||
}
|
@ -9,4 +9,18 @@
|
||||
|
||||
//#include "tinyutf8.h"
|
||||
//#define AU_STRING_IS_TINYUTF_EXPERIMENT
|
||||
using AuString = std::string;
|
||||
|
||||
#if defined(AURORA_ROXTL_STRING_USE_STR_ALLOCATOR)
|
||||
template <class Base_t = std::basic_string<char, std::char_traits<char>, Aurora::Memory::StringAllocator<char>>>
|
||||
struct _AuStdExString : Base_t
|
||||
{
|
||||
using Base_t::Base_t;
|
||||
|
||||
_AuStdExString(const std::string &str) : Base_t(str.begin(), str.end())
|
||||
{}
|
||||
};
|
||||
|
||||
using AuString = _AuStdExString<>;
|
||||
#else
|
||||
using AuString = std::string;
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user