7#if PLATFORM_HAS_FPlatformVirtualMemoryBlock
11#define UE4_TMEMORY_POOL_DO_SANITY_CHECKS (UE_BUILD_DEBUG || (UE_BUILD_DEVELOPMENT && !UE_EDITOR))
53#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
70#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
78 VMBlock.DecommitByPtr(
reinterpret_cast<void *
>(
AlignedPoolStart),
Align(NumBlocks * BlockSize, FPlatformMemory::FPlatformVirtualMemoryBlock::GetCommitAlignment()));
84#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
87 checkf(
NoConcurrentAccess.Increment() == 1,
TEXT(
"TMemoryPool is being accessed on multiple threads. The class is not thread safe, add locking!."));
90 void* Address =
nullptr;
91 if (
LIKELY(NumFreeBlocks > 0))
99#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
100 checkf(Address !=
nullptr,
TEXT(
"NumFreeBlocks and bitmask of the free blocks are not in sync - bug in TMemoryPool"));
104 VMBlock.CommitByPtr(Address,
Align(
Size, FPlatformMemory::FPlatformVirtualMemoryBlock::GetCommitAlignment()));
108#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
109 checkf(
NoConcurrentAccess.Decrement() == 0,
TEXT(
"TMemoryPool is being accessed on multiple threads. The class is not thread safe, add locking!."));
119#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
120 checkf(
WasAllocatedFromThisPool(Ptr, BlockSize),
TEXT(
"Address passed to Free() of a pool of block size %llu was not allocated in it (address: %p, boundaries: %p - %p"),
127 checkf((
reinterpret_cast<SIZE_T>(Ptr) % RequiredAlignment == 0),
TEXT(
"Address passed to Free() of a pool of block size %llu was not aligned to %llu bytes (address: %p)"),
129 (
uint64)RequiredAlignment,
133 checkf(
NoConcurrentAccess.Increment() == 1,
TEXT(
"TMemoryPool is being accessed on multiple threads. The class is not thread safe, add locking!."));
144 VMBlock.DecommitByPtr(Ptr, BlockSize);
146#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
148 checkf(NumFreeBlocks <= NumBlocks,
TEXT(
"Too many frees!"));
150 checkf(
NoConcurrentAccess.Decrement() == 0,
TEXT(
"TMemoryPool is being accessed on multiple threads. The class is not thread safe, add locking!."));
156 return (NumBlocks / 8) + ((NumBlocks & 7) ? 1 : 0);
159 void MarkFree(
void *Ptr)
165#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
166 checkf(BitIndex < NumBlocks,
TEXT(
"Incorrect pointer %p passed to MarkFree()"), Ptr);
169 SIZE_T ByteIndex = BitIndex / 8;
173#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
201#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
232#if UE4_TMEMORY_POOL_DO_SANITY_CHECKS
254 NumFree += FMath::CountBits(*
reinterpret_cast<uint64*
>(
CurPtr));
260 NumFree += FMath::CountBits(
static_cast<uint64>(*
CurPtr));
265 if ((NumBlocks & 0x7) == 0)
267 NumFree += FMath::CountBits(
static_cast<uint64>(*
CurPtr));
276 NumFree += (LastByte & (1 << Idx)) ? 1 : 0;
286 return BlockSize >=
Size;
298 return NumFreeBlocks == NumBlocks;
304 return NumFreeBlocks * BlockSize;
315 printf(
"BlockSize: %llu NumAllocated/TotalBlocks = %llu/%llu\n", (
uint64)BlockSize, (
uint64)(NumBlocks - NumFreeBlocks), (
uint64)NumBlocks);
constexpr T Align(T Val, uint64 Alignment)
Definition AlignmentTemplates.h:18
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define LIKELY(x)
Definition CityHash.cpp:107
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32 Size
Definition VulkanMemory.cpp:4034
Definition ThreadSafeCounter.h:14
constexpr SIZE_T RequiredAlignment
Definition PimplPtr.h:55
@ Bitmask
[FunctionMetadata] [InterfaceMetadata] Metadata that identifies an integral property as a bitmask.
Definition ObjectMacros.h:1760
static UE_FORCEINLINE_HINT void * Memset(void *Dest, uint8 Char, SIZE_T Count)
Definition UnrealMemory.h:119