Skip to content

Commit

Permalink
Merge pull request #168 from WSSDude/feature/allocator-changes
Browse files Browse the repository at this point in the history
Fix Allocator issues reported by ReSharper
  • Loading branch information
psiberx authored Jan 14, 2025
2 parents 929c8e0 + 855ba85 commit fedf842
Showing 1 changed file with 19 additions and 25 deletions.
44 changes: 19 additions & 25 deletions include/RED4ext/Memory/Allocators.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#pragma once
// Disable ReSharper virtual destructor check, as the Allocators are just structs with pointers to functions which are
// copied around.
// ReSharper disable CppPolymorphicClassWithNonVirtualPublicDestructor

#include <cstdint>
#include <type_traits>
#pragma once

#include <RED4ext/Detail/AddressHashes.hpp>
#include <RED4ext/Common.hpp>
#include <RED4ext/Detail/AddressHashes.hpp>
#include <RED4ext/Memory/Pools.hpp>
#include <RED4ext/Relocation.hpp>

#include <cstdint>
#include <type_traits>

namespace RED4ext
{
namespace Memory
Expand All @@ -28,7 +32,7 @@ struct IAllocator
uint32_t aAlignment) const = 0; // 16
virtual void Free(AllocationResult& aAllocation) const = 0; // 20
virtual void sub_28(void* a1) const = 0; // 28
virtual const uint32_t GetHandle() const = 0; // 30
virtual const uint32_t GetHandle() const = 0; // 30

[[deprecated("Use 'GetHandle()' instead.")]] const uint32_t GetId() const
{
Expand Down Expand Up @@ -81,9 +85,9 @@ struct Allocator : IAllocator
static UniversalRelocFunc<alloc_t> alloc(Detail::AddressHashes::Memory_Vault_Alloc);

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

AllocationResult result;
AllocationResult result = {};
alloc(storage, &result, aSize);
if (!result.memory)
{
Expand All @@ -99,9 +103,9 @@ struct Allocator : IAllocator
static UniversalRelocFunc<alloc_t> alloc(Detail::AddressHashes::Memory_Vault_AllocAligned);

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

AllocationResult result;
AllocationResult result = {};
alloc(storage, &result, aSize, aAlignment);
if (!result.memory)
{
Expand All @@ -117,9 +121,9 @@ struct Allocator : IAllocator
static UniversalRelocFunc<realloc_t> realloc(Detail::AddressHashes::Memory_Vault_Realloc);

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

AllocationResult result;
AllocationResult result = {};
realloc(storage, &result, aAllocation, aSize);
if (!result.memory && aSize)
{
Expand All @@ -136,9 +140,9 @@ struct Allocator : IAllocator
static UniversalRelocFunc<realloc_t> realloc(Detail::AddressHashes::Memory_Vault_ReallocAligned);

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();

AllocationResult result;
AllocationResult result = {};
realloc(storage, &result, aAllocation, aSize, aAlignment);
if (!result.memory && aSize)
{
Expand All @@ -154,7 +158,7 @@ struct Allocator : IAllocator
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::Memory_Vault_Free);

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
func(storage, aAllocation);
}

Expand All @@ -164,7 +168,7 @@ struct Allocator : IAllocator
static UniversalRelocFunc<func_t> func(Detail::AddressHashes::Memory_Vault_Unk1);

auto pool = T::Get();
auto storage = pool->storage->GetAllocatorStorage<Vault>();
auto storage = pool->storage->template GetAllocatorStorage<Vault>();
func(storage, a2);
}

Expand Down Expand Up @@ -2712,14 +2716,4 @@ struct GPUM_Buffer_MorphTargetsAllocator : Allocator<GPUM_Buffer_MorphTargets>
{
};
} // namespace Memory

struct [[deprecated("Use 'Memory::IAllocator' instead.")]] IMemoryAllocator : Memory::IAllocator
{
struct [[deprecated("Use 'Memory::AllocationResult' instead.")]] Result : Memory::AllocationResult{};
};

struct [[deprecated("Use 'Memory::EngineAllocator' instead.")]] EngineAllocator : Memory::EngineAllocator{};
struct [[deprecated("Use 'Memory::RTTIAllocator' instead.")]] RTTIAllocator : Memory::RTTIAllocator{};
struct [[deprecated("Use 'Memory::RTTIFunctionAllocator' instead.")]] RTTIFunctionAllocator
: Memory::RTTIFunctionAllocator{};
} // namespace RED4ext

0 comments on commit fedf842

Please sign in to comment.