mirror of
https://github.com/recastnavigation/recastnavigation.git
synced 2026-10-01 22:45:32 +00:00
Add homebrewed rcVector class and tests, and use it to implement rcIntArray. (#318)
This implements most of the std::vector interface, with some minor elisions of infrequently used methods such as "insert", and some STL bookkeeping. Performance is favorable compared to std::vector, and, in some cases, somewhat better than naive code to manually manage a malloc'd dynamic array. BM_FlatArray_Push: 100 iterations in 72889721 nanos: 728897.21 nanos/it BM_FlatArray_Fill: 100 iterations in 2700746 nanos: 27007.46 nanos/it BM_FlatArray_Memset: 100 iterations in 2687810 nanos: 26878.10 nanos/it BM_rcVector_Push: 100 iterations in 51114316 nanos: 511143.16 nanos/it BM_rcVector_PushPreallocated: 100 iterations in 9532106 nanos: 95321.06 nanos/it BM_rcVector_Assign: 100 iterations in 2371534 nanos: 23715.34 nanos/it BM_rcVector_AssignIndices: 100 iterations in 2573052 nanos: 25730.52 nanos/it BM_rcVector_Resize: 100 iterations in 2455761 nanos: 24557.61 nanos/it BM_stdvector_Push: 100 iterations in 71739167 nanos: 717391.67 nanos/it BM_stdvector_PushPreallocated: 100 iterations in 15723737 nanos: 157237.37 nanos/it BM_stdvector_Assign: 100 iterations in 2564985 nanos: 25649.85 nanos/it BM_stdvector_AssignIndices: 100 iterations in 5174923 nanos: 51749.23 nanos/it BM_stdvector_Resize: 100 iterations in 2520054 nanos: 25200.54 nanos/it
This commit is contained in:
committed by
Jakob Botsch Nielsen
parent
18562383f4
commit
fa7debb0c3
@@ -58,29 +58,3 @@ void rcFree(void* ptr)
|
||||
if (ptr)
|
||||
sRecastFreeFunc(ptr);
|
||||
}
|
||||
|
||||
/// @class rcIntArray
|
||||
///
|
||||
/// While it is possible to pre-allocate a specific array size during
|
||||
/// construction or by using the #resize method, certain methods will
|
||||
/// automatically resize the array as needed.
|
||||
///
|
||||
/// @warning The array memory is not initialized to zero when the size is
|
||||
/// manually set during construction or when using #resize.
|
||||
|
||||
/// @par
|
||||
///
|
||||
/// Using this method ensures the array is at least large enough to hold
|
||||
/// the specified number of elements. This can improve performance by
|
||||
/// avoiding auto-resizing during use.
|
||||
void rcIntArray::doResize(int n)
|
||||
{
|
||||
if (!m_cap) m_cap = n;
|
||||
while (m_cap < n) m_cap *= 2;
|
||||
int* newData = (int*)rcAlloc(m_cap*sizeof(int), RC_ALLOC_TEMP);
|
||||
rcAssert(newData);
|
||||
if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(int));
|
||||
rcFree(m_data);
|
||||
m_data = newData;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user