From 8c33b4d742087a3467caba5d049368e5e301eff3 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Fri, 21 Mar 2014 16:35:38 -0700 Subject: Increase the vector reserve as needed when pushing in new items --- Alc/helpers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'Alc/helpers.c') 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). */ -- cgit v1.2.3