11#ifndef JPH_DISABLE_CUSTOM_ALLOCATOR
14template <
typename T,
size_t N>
51 ptrdiff_t diff = inPointer -
reinterpret_cast<const_pointer>(mElements);
52 return diff >= 0 && diff < ptrdiff_t(N);
59 if (mNumElementsUsed + inN > N)
63 pointer result =
reinterpret_cast<pointer>(mElements) + mNumElementsUsed;
64 mNumElementsUsed += inN;
77 if (inOldPointer ==
nullptr)
86 return ReallocateImpl(inOldPointer, inOldSize, inNewSize);
90 pointer base_ptr =
reinterpret_cast<pointer>(mElements) + mNumElementsUsed - inOldSize;
91 if (inOldPointer == base_ptr
92 && mNumElementsUsed - inOldSize + inNewSize <= N)
94 mNumElementsUsed += inNewSize - inOldSize;
99 return ReallocateImpl(inOldPointer, inOldSize, inNewSize);
110 if (inPointer ==
reinterpret_cast<pointer>(mElements) + mNumElementsUsed - inN)
111 mNumElementsUsed -= inN;
117 return this == &inRHS;
122 return this != &inRHS;
126 template <
typename T2>
138 if constexpr (std::is_trivially_copyable<T>())
141 memcpy(new_pointer, inOldPointer, n *
sizeof(T));
146 for (
size_t i = 0; i < n; ++i)
148 new (new_pointer + i) T(std::move(inOldPointer[i]));
149 inOldPointer[i].~T();
156 alignas(T)
uint8 mElements[N *
sizeof(T)];
std::uint8_t uint8
Definition Core.h:482
#define JPH_NAMESPACE_END
Definition Core.h:414
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
STL allocator that forwards to our allocation functions.
Definition STLAllocator.h:17
pointer allocate(size_type inN)
Allocate memory.
Definition STLAllocator.h:50
pointer reallocate(pointer inOldPointer, size_type inOldSize, size_type inNewSize)
Reallocate memory.
Definition STLAllocator.h:63
void deallocate(pointer inPointer, size_type)
Free memory.
Definition STLAllocator.h:70
STL allocator that keeps N elements in a local buffer before falling back to regular allocations.
Definition STLLocalAllocator.h:16
STLLocalAllocator & operator=(const STLLocalAllocator &)=delete
std::false_type propagate_on_container_swap
Definition STLLocalAllocator.h:35
void deallocate(pointer inPointer, size_type inN)
Free memory.
Definition STLLocalAllocator.h:103
const T & const_reference
Definition STLLocalAllocator.h:25
std::false_type is_always_equal
The allocator is not stateless (has local buffer)
Definition STLLocalAllocator.h:30
size_t size_type
Definition STLLocalAllocator.h:26
static constexpr bool has_reallocate
Always implements a reallocate function as we can often reallocate in place.
Definition STLLocalAllocator.h:69
T & reference
Definition STLLocalAllocator.h:24
STLLocalAllocator(const STLLocalAllocator< T2, N > &)
Definition STLLocalAllocator.h:46
STLLocalAllocator(STLLocalAllocator &&)=delete
STLLocalAllocator()=default
Constructor.
bool operator==(const STLLocalAllocator< T, N > &inRHS) const
Allocators are not-stateless, assume if allocator address matches that the allocators are the same.
Definition STLLocalAllocator.h:115
bool operator!=(const STLLocalAllocator< T, N > &inRHS) const
Definition STLLocalAllocator.h:120
const T * const_pointer
Definition STLLocalAllocator.h:23
std::false_type propagate_on_container_move_assignment
Definition STLLocalAllocator.h:34
T * pointer
Definition STLLocalAllocator.h:22
T value_type
General properties.
Definition STLLocalAllocator.h:21
STLLocalAllocator(const STLLocalAllocator &)=delete
pointer allocate(size_type inN)
Allocate memory.
Definition STLLocalAllocator.h:56
ptrdiff_t difference_type
Definition STLLocalAllocator.h:27
pointer reallocate(pointer inOldPointer, size_type inOldSize, size_type inNewSize)
Reallocate memory.
Definition STLLocalAllocator.h:72
std::false_type propagate_on_container_copy_assignment
We cannot copy, move or swap allocators.
Definition STLLocalAllocator.h:33
bool is_local(const_pointer inPointer) const
Check if inPointer is in the local buffer.
Definition STLLocalAllocator.h:49
Default implementation of AllocatorHasReallocate which tells if an allocator has a reallocate functio...
Definition STLAllocator.h:10
static constexpr bool sValue
Definition STLAllocator.h:10
Converting to allocator for other type.
Definition STLLocalAllocator.h:128