mirror of
https://github.com/gnif/LookingGlass.git
synced 2025-10-13 19:08:11 +00:00
[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:
@@ -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