71inline void*
operator new(size_t,
const rcNewTag&,
void* p) {
return p; }
72inline void operator delete(
void*,
const rcNewTag&,
void*) {}
77#define RC_SIZE_MAX INTPTR_MAX
81#if defined(__GNUC__) || defined(__clang__)
82#define rcLikely(x) __builtin_expect((x), true)
83#define rcUnlikely(x) __builtin_expect((x), false)
85#define rcLikely(x) (x)
86#define rcUnlikely(x) (x)
97template <
typename T, rcAllocH
int H>
104 static void construct(T* p,
const T& v) { ::new(
rcNewTag(), (
void*)p) T(v); }
105 static void construct(T* p) { ::new(
rcNewTag(), (
void*)p) T; }
106 static void construct_range(T*
begin, T*
end);
107 static void construct_range(T*
begin, T*
end,
const T& value);
108 static void copy_range(T* dst,
const T*
begin,
const T*
end);
135 void clear() { destroy_range(0, m_size); m_size = 0; }
151 const T*
data()
const {
return m_data; }
155 T*
end() {
return m_data + m_size; }
156 const T*
begin()
const {
return m_data; }
157 const T*
end()
const {
return m_data + m_size; }
165template<
typename T, rcAllocH
int H>
173 T* new_data = allocate_and_copy(count);
179 destroy_range(0, m_size);
186template <
typename T, rcAllocH
int H>
190 T* new_data =
static_cast<T*
>(
rcAlloc(
sizeof(T) * size, H));
193 copy_range(new_data, m_data, m_data + m_size);
198template <
typename T, rcAllocH
int H>
202 reserve(end - begin);
203 m_size = end - begin;
204 copy_range(m_data, begin, end);
207template <
typename T, rcAllocH
int H>
214 construct(m_data + m_size++, value);
218 const rcSizeType new_cap = get_new_capacity(m_cap + 1);
219 T* data = allocate_and_copy(new_cap);
222 construct(data + m_size, value);
223 destroy_range(0, m_size);
230template <
typename T, rcAllocH
int H>
238 return 2 * m_cap > min_capacity ? 2 * m_cap : min_capacity;
241template <
typename T, rcAllocH
int H>
246 destroy_range(size, m_size);
249 else if (size > m_size)
255 construct_range(m_data + m_size, m_data + size, *value);
259 construct_range(m_data + m_size, m_data + size);
265 const rcSizeType new_cap = get_new_capacity(size);
266 T* new_data = allocate_and_copy(new_cap);
271 construct_range(new_data + m_size, new_data + size, *value);
275 construct_range(new_data + m_size, new_data + size);
277 destroy_range(0, m_size);
286template <
typename T, rcAllocH
int H>
292 T* tmp_data = other.m_data;
295 other.m_size = m_size;
296 other.m_data = m_data;
304template <
typename T, rcAllocH
int H>
307 for (T* p = begin; p < end; p++)
314template <
typename T, rcAllocH
int H>
317 for (T* p = begin; p < end; p++)
324template <
typename T, rcAllocH
int H>
329 construct(dst + i, begin[i]);
333template <
typename T, rcAllocH
int H>
378 int v = m_impl.
back();
382 int size()
const {
return static_cast<int>(m_impl.
size()); }
404 inline operator T*() {
return ptr; }
rcAllocHint
Provides hint values to the memory allocator on how long the memory is expected to be used.
Definition RecastAlloc.h:30
@ RC_ALLOC_TEMP
Memory used temporarily within a function.
Definition RecastAlloc.h:32
@ RC_ALLOC_PERM
Memory will persist after a function call.
Definition RecastAlloc.h:31
void * rcAlloc(size_t size, rcAllocHint hint)
Allocates a memory block.
Definition RecastAlloc.cpp:40
intptr_t rcSizeType
Signed to avoid warnings when comparing to int loop indexes, and common error with comparing to zero.
Definition RecastAlloc.h:76
void() rcFreeFunc(void *ptr)
A memory deallocation function.
Definition RecastAlloc.h:45
void rcFree(void *ptr)
Deallocates a memory block.
Definition RecastAlloc.cpp:45
#define RC_SIZE_MAX
Definition RecastAlloc.h:77
#define rcUnlikely(x)
Definition RecastAlloc.h:86
void *() rcAllocFunc(size_t size, rcAllocHint hint)
A memory allocation function.
Definition RecastAlloc.h:40
#define rcLikely(x)
Macros to hint to the compiler about the likeliest branch.
Definition RecastAlloc.h:85
void rcAllocSetCustom(rcAllocFunc *allocFunc, rcFreeFunc *freeFunc)
Sets the base custom allocation functions to be used by Recast.
Definition RecastAlloc.cpp:34
#define rcAssert(expression)
Definition RecastAssert.h:41
Legacy class. Prefer rcVector<int>.
Definition RecastAlloc.h:368
void clear()
Definition RecastAlloc.h:375
int pop()
Definition RecastAlloc.h:376
void resize(int size)
Definition RecastAlloc.h:374
rcIntArray()
Definition RecastAlloc.h:371
int & operator[](int index)
Definition RecastAlloc.h:383
int operator[](int index) const
Definition RecastAlloc.h:384
rcIntArray(int n)
Definition RecastAlloc.h:372
void push(int item)
Definition RecastAlloc.h:373
int size() const
Definition RecastAlloc.h:382
Definition RecastAlloc.h:356
rcPermVector()
Definition RecastAlloc.h:359
rcPermVector(const rcPermVector< T > &other)
Definition RecastAlloc.h:362
rcPermVector(rcSizeType size, const T &value)
Definition RecastAlloc.h:361
rcPermVector(const T *begin, const T *end)
Definition RecastAlloc.h:363
rcPermVector(rcSizeType size)
Definition RecastAlloc.h:360
A simple helper class used to delete an array when it goes out of scope.
Definition RecastAlloc.h:390
rcScopedDelete()
Constructs an instance with a null pointer.
Definition RecastAlloc.h:395
rcScopedDelete(T *p)
Constructs an instance with the specified pointer.
Definition RecastAlloc.h:399
~rcScopedDelete()
Definition RecastAlloc.h:400
Definition RecastAlloc.h:344
rcTempVector(rcSizeType size)
Definition RecastAlloc.h:348
rcTempVector(const rcTempVector< T > &other)
Definition RecastAlloc.h:350
rcTempVector(const T *begin, const T *end)
Definition RecastAlloc.h:351
rcTempVector(rcSizeType size, const T &value)
Definition RecastAlloc.h:349
rcTempVector()
Definition RecastAlloc.h:347
Variable-sized storage type.
Definition RecastAlloc.h:99
T * begin()
Definition RecastAlloc.h:154
bool reserve(rcSizeType size)
Definition RecastAlloc.h:166
T * end()
Definition RecastAlloc.h:155
const T * data() const
Definition RecastAlloc.h:151
void resize(rcSizeType size, const T &value)
Definition RecastAlloc.h:133
T * data()
Definition RecastAlloc.h:152
rcSizeType capacity() const
Definition RecastAlloc.h:141
T & back()
Definition RecastAlloc.h:150
void assign(const T *begin, const T *end)
Definition RecastAlloc.h:199
const T & operator[](rcSizeType i) const
Definition RecastAlloc.h:144
rcSizeType size_type
Definition RecastAlloc.h:116
rcVectorBase(rcSizeType count)
Definition RecastAlloc.h:121
const T * begin() const
Definition RecastAlloc.h:156
const T * end() const
Definition RecastAlloc.h:157
void pop_back()
Definition RecastAlloc.h:138
void resize(rcSizeType size)
Definition RecastAlloc.h:132
rcVectorBase()
Definition RecastAlloc.h:119
T & operator[](rcSizeType i)
Definition RecastAlloc.h:145
rcVectorBase(const rcVectorBase< T, H > &other)
Definition RecastAlloc.h:120
const T & back() const
Definition RecastAlloc.h:149
~rcVectorBase()
Definition RecastAlloc.h:124
T value_type
Definition RecastAlloc.h:117
void push_back(const T &value)
Definition RecastAlloc.h:208
rcVectorBase(const T *begin, const T *end)
Definition RecastAlloc.h:123
rcVectorBase & operator=(const rcVectorBase< T, H > &other)
rcVectorBase(rcSizeType count, const T &value)
Definition RecastAlloc.h:122
bool empty() const
Definition RecastAlloc.h:142
void clear()
Definition RecastAlloc.h:135
rcSizeType size() const
Definition RecastAlloc.h:140
T & front()
Definition RecastAlloc.h:148
void swap(rcVectorBase< T, H > &other)
Definition RecastAlloc.h:287
const T & front() const
Definition RecastAlloc.h:147
void assign(rcSizeType count, const T &value)
Definition RecastAlloc.h:129
An implementation of operator new usable for placement new.
Definition RecastAlloc.h:70