[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:
1 parent
ba527761ef
commit
e6df0acad9
5 files changed
+61
-44
No files matched your search
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user