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 inline STLTempAllocator(TempAllocator &inAllocator) : mAllocator(inAllocator) { }
32
34 template <typename T2>
35 inline explicit STLTempAllocator(const STLTempAllocator<T2> &inRHS) : mAllocator(inRHS.GetAllocator()) { }
36
39 {
40 return (pointer)mAllocator.Allocate(uint(inN * sizeof(value_type)));
41 }
42
44 inline void deallocate(pointer inPointer, size_type inN)
45 {
46 mAllocator.Free(inPointer, uint(inN * sizeof(value_type)));
47 }
48
50 inline bool operator == (const STLTempAllocator<T> &) const
51 {
52 return true;
53 }
54
55 inline bool operator != (const STLTempAllocator<T> &) const
56 {
57 return false;
58 }
59
61 template <typename T2>
62 struct rebind
63 {
65 };
66
69 {
70 return mAllocator;
71 }
72
73private:
74 TempAllocator & mAllocator;
75};
76
unsigned int uint
Definition: Core.h:309
#define JPH_NAMESPACE_END
Definition: Core.h:240
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
STL allocator that wraps around TempAllocator.
Definition: STLTempAllocator.h:14
T * pointer
Pointer to type.
Definition: STLTempAllocator.h:19
bool operator==(const STLTempAllocator< T > &) const
Allocators are stateless so assumed to be equal.
Definition: STLTempAllocator.h:50
T & reference
Definition: STLTempAllocator.h:24
ptrdiff_t difference_type
Definition: STLTempAllocator.h:28
STLTempAllocator(const STLTempAllocator< T2 > &inRHS)
Constructor from other allocator.
Definition: STLTempAllocator.h:35
pointer allocate(size_type inN)
Allocate memory.
Definition: STLTempAllocator.h:38
STLTempAllocator(TempAllocator &inAllocator)
Constructor.
Definition: STLTempAllocator.h:31
bool operator!=(const STLTempAllocator< T > &) const
Definition: STLTempAllocator.h:55
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:44
size_t size_type
Definition: STLTempAllocator.h:27
TempAllocator & GetAllocator() const
Get our temp allocator.
Definition: STLTempAllocator.h:68
T value_type
Definition: STLTempAllocator.h:16
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:63