[common] vector: eliminate double allocation when possible

This commit creates two constructor/destructor pairs for vector:
* vector_alloc/vector_free dynamically allocates the vector itself
* vector_create/vector_destroy uses existing Vector objects
This commit is contained in:
Quantum
2021-08-27 00:27:16 -04:00
committed by Geoffrey McRae
parent ba527761ef
commit e6df0acad9
5 changed files with 61 additions and 44 deletions

View File

@@ -31,9 +31,14 @@ typedef struct Vector
}
Vector;
Vector * vector_create(size_t itemSize, size_t capacity);
// Dynamically allocates the vector
Vector * vector_alloc(size_t itemSize, size_t capacity);
void vector_free(Vector * vector);
// Uses existing vector, but dynamically allocates storage
bool vector_create(Vector * vector, size_t itemSize, size_t capacity);
void vector_destroy(Vector * vector);
inline static size_t vector_size(Vector * vector)
{
return vector->size;