UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DetourAlloc.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Modified version of Recast/Detour's source file
3
4//
5// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
6//
7// This software is provided 'as-is', without any express or implied
8// warranty. In no event will the authors be held liable for any damages
9// arising from the use of this software.
10// Permission is granted to anyone to use this software for any purpose,
11// including commercial applications, and to alter it and redistribute it
12// freely, subject to the following restrictions:
13// 1. The origin of this software must not be misrepresented; you must not
14// claim that you wrote the original software. If you use this software
15// in a product, an acknowledgment in the product documentation would be
16// appreciated but is not required.
17// 2. Altered source versions must be plainly marked as such, and must not be
18// misrepresented as being the original software.
19// 3. This notice may not be removed or altered from any source distribution.
20//
21
22#ifndef DETOURALLOCATOR_H
23#define DETOURALLOCATOR_H
24
25#include "CoreMinimal.h"
26#include "Detour/DetourAssert.h"
27
28//@UE BEGIN Adding support for memory tracking.
49//@UE END Adding support for memory tracking.
50
52// @param[in] size The size, in bytes of memory, to allocate.
53// @param[in] rcAllocHint A hint to the allocator on how long the memory is expected to be in use.
54// @return A pointer to the beginning of the allocated memory block, or null if the allocation failed.
56typedef void* (dtAllocFunc)(int size, dtAllocHint hint);
57
61//@UE BEGIN Adding support for memory tracking.
62typedef void (dtFreeFunc)(void* ptr, dtAllocHint hint);
63//@UE END Adding support for memory tracking.
64
69
75NAVMESH_API void* dtAlloc(int size, dtAllocHint hint);
76
80//@UE BEGIN Adding support for memory tracking.
81NAVMESH_API void dtFree(void* ptr, dtAllocHint hint);
82//@UE END Adding support for memory tracking.
83
84NAVMESH_API void dtMemCpy(void* dst, void* src, int size);
85
88template<class T> class dtScopedDelete
89{
90 T* ptr;
91 inline T* operator=(T* p);
92public:
93
95 inline dtScopedDelete() : ptr(0) {}
96 inline dtScopedDelete(int n) { ptr = n ? (T*)dtAlloc(sizeof(T)*n, DT_ALLOC_TEMP) : 0; }
97
100 inline dtScopedDelete(T* p) : ptr(p) {}
102
105 inline operator T*() { return ptr; }
106 inline T* get() { return ptr; }
107};
108
111{
112 int* m_data;
113 int m_size, m_cap;
114 inline dtIntArray(const dtIntArray&);
115 inline dtIntArray& operator=(const dtIntArray&);
116public:
117
119 inline dtIntArray() : m_data(0), m_size(0), m_cap(0) {}
120
123 inline dtIntArray(int n) : m_data(0), m_size(0), m_cap(0) { resize(n); }
124 inline ~dtIntArray() { dtFree(m_data, DT_ALLOC_TEMP); }
125
128 void resize(int n);
129
132 inline void push(int item) { resize(m_size+1); m_data[m_size-1] = item; }
133
136 inline int pop() { if (m_size > 0) m_size--; return m_data[m_size]; }
137
141 inline const int& operator[](int i) const { return m_data[i]; }
142
146 inline int& operator[](int i) { return m_data[i]; }
147
149 inline int size() const { return m_size; }
150
151 inline int* getData() const { return m_data; }
152
153 void copy(const dtIntArray& src);
154
155 bool contains(int v) const
156 {
157 for (int i = 0; i < m_size; i++)
158 if (m_data[i] == v)
159 return true;
160
161 return false;
162 }
163};
164
166template<class T, dtAllocHint TAllocHint = DT_ALLOC_TEMP> //UE Adding support for memory tracking.
168{
169 T* m_data;
170 int m_size, m_cap;
171
172 inline dtChunkArray(const dtChunkArray&);
173 inline dtChunkArray& operator=(const dtChunkArray&);
174public:
175
177 inline dtChunkArray() : m_data(0), m_size(0), m_cap(0){}
178
181 inline dtChunkArray(int n) : m_data(0), m_size(0), m_cap(0){ resize(n); }
182 inline ~dtChunkArray() { dtFree(m_data, TAllocHint); }
183
186 void resize(int n);
187
190 inline void push(T item) { resize(m_size+1); m_data[m_size-1] = item; }
191
194 inline T pop() { if (m_size > 0) m_size--; return m_data[m_size]; }
195
199 inline const T& operator[](int i) const { return m_data[i]; }
200
204 inline T& operator[](int i) { return m_data[i]; }
205
207 inline int size() const { return m_size; }
208};
209
210template<class T, dtAllocHint TAllocHint>
212{
213 if (n > m_cap)
214 {
215 if (!m_cap) m_cap = n;
216 while (m_cap < n) m_cap += 32;
217 T* newData = (T*)dtAlloc(m_cap*sizeof(T), TAllocHint);
218 if (m_size && newData) dtMemCpy(newData, m_data, m_size*sizeof(T));
219 dtFree(m_data, TAllocHint);
220 m_data = newData;
221 }
222 m_size = n;
223}
224
225#endif
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
void() dtFreeFunc(void *ptr, dtAllocHint hint)
Definition DetourAlloc.h:62
dtAllocHint
Provides hint values on how the memory is expected to be used. Typically used by external memory allo...
Definition DetourAlloc.h:31
@ DT_ALLOC_PERM_PATH_QUEUE
Definition DetourAlloc.h:40
@ DT_ALLOC_PERM_AVOIDANCE
Definition DetourAlloc.h:33
@ DT_ALLOC_PERM_TILE_DYNLINK_CLUSTER
Definition DetourAlloc.h:45
@ DT_ALLOC_PERM_TILE_LINK_BUILDER
Definition DetourAlloc.h:47
@ DT_ALLOC_TEMP
Memory used temporarily within a function.
Definition DetourAlloc.h:32
@ DT_ALLOC_PERM_NAVMESH
Definition DetourAlloc.h:36
@ DT_ALLOC_PERM_PROXIMITY_GRID
Definition DetourAlloc.h:41
@ DT_ALLOC_PERM_LOOKUP
Definition DetourAlloc.h:35
@ DT_ALLOC_PERM_NODE_POOL
Definition DetourAlloc.h:38
@ DT_ALLOC_PERM_TILE_CACHE_LAYER
Definition DetourAlloc.h:42
@ DT_ALLOC_PERM_TILES
Definition DetourAlloc.h:46
@ DT_ALLOC_PERM_CROWD
Definition DetourAlloc.h:34
@ DT_ALLOC_PERM_TILE_DYNLINK_OFFMESH
Definition DetourAlloc.h:44
@ DT_ALLOC_PERM_NAVQUERY
Definition DetourAlloc.h:37
@ DT_ALLOC_PERM_TILE_DATA
Definition DetourAlloc.h:43
@ DT_ALLOC_PERM_PATH_CORRIDOR
Definition DetourAlloc.h:39
NAVMESH_API void * dtAlloc(int size, dtAllocHint hint)
Definition DetourAlloc.cpp:43
NAVMESH_API void dtAllocSetCustom(dtAllocFunc *allocFunc, dtFreeFunc *freeFunc)
Definition DetourAlloc.cpp:37
NAVMESH_API void dtMemCpy(void *dst, void *src, int size)
Definition DetourAlloc.cpp:56
void *() dtAllocFunc(int size, dtAllocHint hint)
A memory allocation function.
Definition DetourAlloc.h:56
NAVMESH_API void dtFree(void *ptr, dtAllocHint hint)
Definition DetourAlloc.cpp:49
char * dst
Definition lz4.h:735
A simple dynamic array of integers.
Definition DetourAlloc.h:168
int size() const
The current size of the integer array.
Definition DetourAlloc.h:207
dtChunkArray()
Constructs an instance with an initial array size of zero.
Definition DetourAlloc.h:177
const T & operator[](int i) const
Definition DetourAlloc.h:199
T pop()
Definition DetourAlloc.h:194
~dtChunkArray()
Definition DetourAlloc.h:182
dtChunkArray(int n)
Definition DetourAlloc.h:181
void push(T item)
Definition DetourAlloc.h:190
T & operator[](int i)
Definition DetourAlloc.h:204
void resize(int n)
Definition DetourAlloc.h:211
A simple dynamic array of integers.
Definition DetourAlloc.h:111
~dtIntArray()
Definition DetourAlloc.h:124
void resize(int n)
Definition DetourAlloc.cpp:75
dtIntArray()
Constructs an instance with an initial array size of zero.
Definition DetourAlloc.h:119
const int & operator[](int i) const
Definition DetourAlloc.h:141
void push(int item)
Definition DetourAlloc.h:132
int & operator[](int i)
Definition DetourAlloc.h:146
bool contains(int v) const
Definition DetourAlloc.h:155
dtIntArray(int n)
Definition DetourAlloc.h:123
int size() const
The current size of the integer array.
Definition DetourAlloc.h:149
int pop()
Definition DetourAlloc.h:136
int * getData() const
Definition DetourAlloc.h:151
void copy(const dtIntArray &src)
Definition DetourAlloc.cpp:89
Definition DetourAlloc.h:89
dtScopedDelete()
Constructs an instance with a null pointer.
Definition DetourAlloc.h:95
dtScopedDelete(T *p)
Definition DetourAlloc.h:100
T * get()
Definition DetourAlloc.h:106
~dtScopedDelete()
Definition DetourAlloc.h:101
dtScopedDelete(int n)
Definition DetourAlloc.h:96
float v
Definition radaudio_mdct.cpp:62