33 virtual void Free(
void *inAddress,
uint inSize) = 0;
45 if constexpr (needs_aligned_allocate)
48 mBase =
static_cast<uint8 *
>(JPH::Allocate(inSize));
55 if constexpr (needs_aligned_allocate)
70 size_t new_top = mTop +
AlignUp(inSize, alignment_size);
73 Trace(
"TempAllocator: Out of memory trying to allocate %u bytes", inSize);
76 void *address = mBase + mTop;
83 virtual void Free(
void *inAddress,
uint inSize)
override
85 if (inAddress ==
nullptr)
91 mTop -=
AlignUp(inSize, alignment_size);
92 if (mBase + mTop != inAddress)
94 Trace(
"TempAllocator: Freeing in the wrong order");
121 return mTop +
AlignUp(inSize, alignment_size) <= mSize;
127 return inAddress >= mBase && inAddress < mBase + mSize;
148 if constexpr (needs_aligned_allocate)
151 return JPH::Allocate(inSize);
158 virtual void Free(
void *inAddress, [[maybe_unused]]
uint inSize)
override
160 if (inAddress !=
nullptr)
162 if constexpr (needs_aligned_allocate)
165 JPH::Free(inAddress);
185 if (mAllocator.CanAllocate(inSize))
186 return mAllocator.Allocate(inSize);
188 return mFallbackAllocator.Allocate(inSize);
192 virtual void Free(
void *inAddress,
uint inSize)
override
194 if (inAddress ==
nullptr)
200 if (mAllocator.OwnsMemory(inAddress))
201 mAllocator.Free(inAddress, inSize);
203 mFallbackAllocator.Free(inAddress, inSize);
std::uint8_t uint8
Definition Core.h:578
#define JPH_DEFAULT_ALLOCATE_ALIGNMENT
Definition Core.h:620
#define JPH_EXPORT
Definition Core.h:310
unsigned int uint
Definition Core.h:577
#define JPH_NAMESPACE_END
Definition Core.h:494
#define JPH_NAMESPACE_BEGIN
Definition Core.h:488
TraceFunction Trace
Definition IssueReporting.cpp:16
#define JPH_ASSERT(...)
Definition IssueReporting.h:28
T AlignUp(T inV, uint64 inAlignment)
Align inV up to the next inAlignment bytes.
Definition Math.h:168
AlignedFreeFunction AlignedFree
Definition Memory.cpp:72
AlignedAllocateFunction AlignedAllocate
Definition Memory.cpp:71
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:51
#define JPH_RVECTOR_ALIGNMENT
Definition Real.h:34
Class that makes another class non-copyable. Usage: Inherit from NonCopyable.
Definition NonCopyable.h:11
Definition TempAllocator.h:16
virtual void Free(void *inAddress, uint inSize)=0
Frees inSize bytes of memory located at inAddress.
virtual void * Allocate(uint inSize)=0
Allocates inSize bytes of memory, returned memory address must be alignment_size byte aligned.
virtual ~TempAllocator()=default
Destructor.
Default implementation of the temp allocator that allocates a large block through malloc upfront.
Definition TempAllocator.h:38
size_t GetUsage() const
Get current usage in bytes of the buffer.
Definition TempAllocator.h:113
size_t GetSize() const
Get the total size of the fixed buffer.
Definition TempAllocator.h:107
bool OwnsMemory(const void *inAddress) const
Check if memory block at inAddress is owned by this allocator.
Definition TempAllocator.h:125
virtual ~TempAllocatorImpl() override
Destructor, frees the block.
Definition TempAllocator.h:52
JPH_OVERRIDE_NEW_DELETE TempAllocatorImpl(size_t inSize)
Constructs the allocator with a maximum allocatable size of inSize.
Definition TempAllocator.h:43
virtual void Free(void *inAddress, uint inSize) override
Frees inSize bytes of memory located at inAddress.
Definition TempAllocator.h:83
bool CanAllocate(uint inSize) const
Check if an allocation of inSize can be made in this fixed buffer allocator.
Definition TempAllocator.h:119
bool IsEmpty() const
Check if no allocations have been made.
Definition TempAllocator.h:101
virtual void * Allocate(uint inSize) override
Allocates inSize bytes of memory, returned memory address must be alignment_size byte aligned.
Definition TempAllocator.h:62
Implementation of the TempAllocator that tries to allocate from a large preallocated block,...
Definition TempAllocator.h:172
JPH_OVERRIDE_NEW_DELETE TempAllocatorImplWithMallocFallback(uint inSize)
Constructs the allocator with an initial fixed block if inSize.
Definition TempAllocator.h:177
virtual void Free(void *inAddress, uint inSize) override
Frees inSize bytes of memory located at inAddress.
Definition TempAllocator.h:192
virtual void * Allocate(uint inSize) override
Allocates inSize bytes of memory, returned memory address must be alignment_size byte aligned.
Definition TempAllocator.h:183
Definition TempAllocator.h:139
virtual void Free(void *inAddress, uint inSize) override
Frees inSize bytes of memory located at inAddress.
Definition TempAllocator.h:158
virtual JPH_OVERRIDE_NEW_DELETE void * Allocate(uint inSize) override
Allocates inSize bytes of memory, returned memory address must be alignment_size byte aligned.
Definition TempAllocator.h:144