C Collections

cvector · Section 3

cvec_reset

cvec_reset - clear all elements and shrink back to minimum capacity (type-inferred)

C Collections (libccollections, -lccollections)

#include <ccollections/cvector.h>
 
cvec_reset(v);

A wrapper for cvector_reset() that removes every element and then tries to
shrink the backing buffer back to the minimum capacity of 4 elements. The
element count becomes 0 whether or not the shrink works. If the
reallocation fails the larger buffer stays in place, which isn't an error
and isn't reported.
 
The vector stays usable after the call and keeps its element type, so
you can push into it again with no new declaration.

v    Vector to reset

The element count becomes 0. The capacity goes back to the minimum of 4
when the reallocation succeeds and stays as it was otherwise.
 
If the vector holds pointers to heap buffers, the elements are not freed
one by one, so the caller has to free the element data first when that is
needed.
 
This call invalidates every pointer obtained earlier from
cvec_data_ptr(3) or cvec_at_ptr(3). The macro asserts when v is NULL.

cvec_construct(vec, int);
cvec_push(vec, 1);
cvec_push(vec, 2);
cvec_reset(vec);
// cvec_size(vec) == 0, vec is still a usable int vector
cvec_destroy(vec);

cvector_reset(3), cvector_destroy(3), cvec_size(3)