Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
STLTempAllocator.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
10
12template <typename T>
14{
15public:
16 using value_type = T;
17
19 using pointer = T *;
20 using const_pointer = const T *;
21
24 using reference = T &;
25 using const_reference = const T &;
26
27 using size_type = size_t;
28 using difference_type = ptrdiff_t;
29
31 using is_always_equal = std::false_type;
32
34 inline STLTempAllocator(TempAllocator &inAllocator) : mAllocator(inAllocator) { }
35
37 template <typename T2>
38 inline explicit STLTempAllocator(const STLTempAllocator<T2> &inRHS) : mAllocator(inRHS.GetAllocator()) { }
39
42 {
43 return pointer(mAllocator.Allocate(uint(inN * sizeof(value_type))));
44 }
45
47 inline void deallocate(pointer inPointer, size_type inN)
48 {
49 mAllocator.Free(inPointer, uint(inN * sizeof(value_type)));
50 }
51
53 inline bool operator == (const STLTempAllocator<T> &inRHS) const
54 {
55 return &mAllocator == &inRHS.mAllocator;
56 }
57
58 inline bool operator != (const STLTempAllocator<T> &inRHS) const
59 {
60 return &mAllocator != &inRHS.mAllocator;
61 }
62
64 template <typename T2>
65 struct rebind
66 {
68 };
69
72 {
73 return mAllocator;
74 }
75
76private:
77 TempAllocator & mAllocator;
78};
79
unsigned int uint
Definition Core.h:446
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
STL allocator that wraps around TempAllocator.
Definition STLTempAllocator.h:14
std::false_type is_always_equal
The allocator is not stateless (depends on the temp allocator)
Definition STLTempAllocator.h:31
T * pointer
Pointer to type.
Definition STLTempAllocator.h:19
T & reference
Definition STLTempAllocator.h:24
bool operator!=(const STLTempAllocator< T > &inRHS) const
Definition STLTempAllocator.h:58
ptrdiff_t difference_type
Definition STLTempAllocator.h:28
STLTempAllocator(const STLTempAllocator< T2 > &inRHS)
Constructor from other allocator.
Definition STLTempAllocator.h:38
pointer allocate(size_type inN)
Allocate memory.
Definition STLTempAllocator.h:41
STLTempAllocator(TempAllocator &inAllocator)
Constructor.
Definition STLTempAllocator.h:34
const T & const_reference
Definition STLTempAllocator.h:25
const T * const_pointer
Definition STLTempAllocator.h:20
void deallocate(pointer inPointer, size_type inN)
Free memory.
Definition STLTempAllocator.h:47
size_t size_type
Definition STLTempAllocator.h:27
TempAllocator & GetAllocator() const
Get our temp allocator.
Definition STLTempAllocator.h:71
T value_type
Definition STLTempAllocator.h:16
bool operator==(const STLTempAllocator< T > &inRHS) const
Allocators are not-stateless, assume if allocator address matches that the allocators are the same.
Definition STLTempAllocator.h:53
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 JPH_RVECTOR_ALIGNMENT byte aligned.
Converting to allocator for other type.
Definition STLTempAllocator.h:66