diff options
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r-- | Alc/helpers.c | 9 |
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). */ |