Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
MallocThreadSafeProxy.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Misc/AssertionMacros.h"
7#include "HAL/MemoryBase.h"
8#include "Misc/ScopeLock.h"
9
10/**
11 * FMalloc proxy that synchronizes access, making the used malloc thread safe.
12 */
14{
15private:
16 /** Malloc we're based on, aka using under the hood */
18 /** Object used for synchronization via a scoped lock */
20
21public:
22 /**
23 * Constructor for thread safe proxy malloc that takes a malloc to be used and a
24 * synchronization object used via FScopeLock as a parameter.
25 *
26 * @param InMalloc FMalloc that is going to be used for actual allocations
27 */
29 : UsedMalloc( InMalloc )
30 {}
31
32 virtual void InitializeStatsMetadata() override
33 {
35 }
36
37 /**
38 * Malloc
39 */
40 virtual void* Malloc( SIZE_T Size, uint32 Alignment ) override
41 {
43 return UsedMalloc->Malloc( Size, Alignment );
44 }
45
46 /**
47 * Realloc
48 */
49 virtual void* Realloc( void* Ptr, SIZE_T NewSize, uint32 Alignment ) override
50 {
52 return UsedMalloc->Realloc( Ptr, NewSize, Alignment );
53 }
54
55 /**
56 * Free
57 */
58 virtual void Free( void* Ptr ) override
59 {
60 if( Ptr )
61 {
64 }
65 }
66
67 /** Writes allocator stats from the last update into the specified destination. */
68 virtual void GetAllocatorStats( FGenericMemoryStats& out_Stats ) override
69 {
72 }
73
74 /** Dumps allocator stats to an output device. */
75 virtual void DumpAllocatorStats( class FOutputDevice& Ar ) override
76 {
79 }
80
81 /**
82 * Validates the allocator's heap
83 */
84 virtual bool ValidateHeap() override
85 {
88 }
89
90 virtual bool Exec( UWorld* InWorld, const TCHAR* Cmd, FOutputDevice& Ar ) override
91 {
93 return UsedMalloc->Exec( InWorld, Cmd, Ar);
94 }
95
96 /**
97 * If possible determine the size of the memory allocated at the given address
98 *
99 * @param Original - Pointer to memory we are checking the size of
100 * @param SizeOut - If possible, this value is set to the size of the passed in pointer
101 * @return true if succeeded
102 */
103 virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut) override
104 {
106 return UsedMalloc->GetAllocationSize(Original,SizeOut);
107 }
108
109 virtual const TCHAR* GetDescriptiveName() override
110 {
112 check(UsedMalloc);
114 }
115
116 virtual void Trim(bool bTrimThreadCaches) override
117 {
119 check(UsedMalloc);
120 UsedMalloc->Trim(bTrimThreadCaches);
121 }
122
123 virtual bool IsInternallyThreadSafe() const override
124 {
125 return true;
126 }
127
128 virtual void OnMallocInitialized() override
129 {
131 }
132
133 virtual void OnPreFork() override
134 {
136 }
137
138 virtual void OnPostFork() override
139 {
141 }
142};
#define check(expr)
FWindowsCriticalSection FCriticalSection
virtual const TCHAR * GetDescriptiveName()
Definition MemoryBase.h:208
virtual void Free(void *Original)=0
virtual void OnMallocInitialized()
Definition MemoryBase.h:216
virtual void OnPreFork()
Definition MemoryBase.h:221
virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut)
Definition MemoryBase.h:133
virtual void * Malloc(SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)=0
virtual bool ValidateHeap()
Definition MemoryBase.h:198
virtual void GetAllocatorStats(FGenericMemoryStats &out_Stats)
virtual void DumpAllocatorStats(class FOutputDevice &Ar)
Definition MemoryBase.h:181
virtual void Trim(bool bTrimThreadCaches)
Definition MemoryBase.h:141
virtual void * Realloc(void *Original, SIZE_T Count, uint32 Alignment=DEFAULT_ALIGNMENT)=0
virtual void OnPostFork()
Definition MemoryBase.h:226
virtual void InitializeStatsMetadata()
virtual void OnPreFork() override
virtual bool Exec(UWorld *InWorld, const TCHAR *Cmd, FOutputDevice &Ar) override
virtual void DumpAllocatorStats(class FOutputDevice &Ar) override
virtual bool GetAllocationSize(void *Original, SIZE_T &SizeOut) override
virtual void GetAllocatorStats(FGenericMemoryStats &out_Stats) override
virtual bool ValidateHeap() override
FMallocThreadSafeProxy(FMalloc *InMalloc)
virtual const TCHAR * GetDescriptiveName() override
virtual void * Malloc(SIZE_T Size, uint32 Alignment) override
virtual void InitializeStatsMetadata() override
virtual void Trim(bool bTrimThreadCaches) override
virtual void OnPostFork() override
virtual bool IsInternallyThreadSafe() const override
FCriticalSection SynchronizationObject
virtual void OnMallocInitialized() override
virtual void Free(void *Ptr) override
virtual void * Realloc(void *Ptr, SIZE_T NewSize, uint32 Alignment) override
UE_NODISCARD_CTOR FScopeLock(FCriticalSection *InSynchObject)
Definition ScopeLock.h:35