aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-03-21 16:35:38 -0700
committerChris Robinson <[email protected]>2014-03-21 16:35:38 -0700
commit8c33b4d742087a3467caba5d049368e5e301eff3 (patch)
treeeddb440ba1f170338f03c599e38139fd3f67943d /Alc/helpers.c
parent983fa4630a8ba68f2e446cc0b05234fd5399c9bd (diff)
Increase the vector reserve as needed when pushing in new items
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 69c49db1..a89883ed 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -701,13 +701,20 @@ void WriteUnlock(RWLock *lock)
}
-ALboolean vector_reserve(void *ptr, size_t orig_count, size_t base_size, size_t obj_count, size_t obj_size)
+ALboolean vector_reserve(void *ptr, size_t orig_count, size_t base_size, size_t obj_count, size_t obj_size, ALboolean exact)
{
if(orig_count < obj_count)
{
vector_ *vecptr = ptr;
void *temp;
+ /* Use the next power-of-2 size if we don't need to allocate the exact
+ * amount. This is preferred when regularly increasing the vector since
+ * it means fewer reallocations. Though it means it also wastes some
+ * memory. */
+ if(exact == AL_FALSE)
+ obj_count = NextPowerOf2(obj_count);
+
/* Need to be explicit with the caller type's base size, because it
* could have extra padding before the start of the array (that is,
* sizeof(*vector_) may not equal base_size). */