VecClear
Description
Set the vector length to 0 while keeping the allocated capacity. Element payloads are deinitialized via the configured copy_deinit handler when present.
Parameters
| Name | Direction | Description |
|---|---|---|
v |
in,out | Vector handle. |
Success
Returns to the caller. The vector length is now 0; the allocated capacity and data buffer are preserved. When copy_deinit is configured it has been invoked on each previously-stored element.
Failure
Function cannot fail.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Buf.h:62:
/// TAGS: Buf, Clear, Reuse
///
#define BufClear(b) VecClear(b)
// Read-only accessors. The leading `((void)0, ...)` makes each macro a
- In
Memory.h:87:
/// TAGS: Str, Memory, Clear
///
#define StrClear(str) VecClear(str)
///
- In
VecInt.c:124:
// Memory operations
case VEC_INT_CLEAR : {
VecClear(vec);
break;
}- In
VecCharPtr.c:156:
case VEC_CHAR_PTR_CLEAR : {
// VecClear automatically calls char_ptr_deinit on each element
VecClear(vec);
break;
}- In
VecStr.c:178:
case VEC_STR_CLEAR : {
// VecClear automatically calls StrDeinit on each element
VecClear(vec);
break;
}- In
Io.c:1093:
LOG_FATAL("buf_write_fmt: NULL out or fmtstr");
}
VecClear(out);
return render_binary_fmt((Str *)out, fmtstr, argv, argc);
}- In
Ops.c:103:
// Test with a vector of even length
VecClear(&vec);
int even_values[] = {10, 20, 30, 40};
for (int i = 0; i < 4; i++) {- In
Memory.c:217:
// Test VecClear function
bool test_vec_clear(void) {
WriteFmt("Testing VecClear\n");
DefaultAllocator alloc = DefaultAllocatorInit();- In
Memory.c:238:
// Clear the vector
VecClear(&vec);
// Length should now be 0
- In
Memory.c:447:
// Str the buffer -- including the NUL sentinel -- must be zeroed.
bool test_clear_str_scrubs_sentinel(void) {
WriteFmt("Testing VecClear scrubs Str sentinel byte\n");
DefaultAllocator local = DefaultAllocatorInit();- In
Memory.c:465:
// mutation. A one-character Str has capacity == 1 exactly.
bool test_clear_str_cap1_scrubs_sentinel(void) {
WriteFmt("Testing VecClear scrubs single-char Str (capacity 1)\n");
DefaultAllocator local = DefaultAllocatorInit();- In
Memory.c:482:
// clear_vec @ 84:18 / 84:20 (scrub MemSet stride forced to 42).
bool test_clear_large_char_vec_scrub_stride(void) {
WriteFmt("Testing VecClear scrub stride on a large char vector\n");
DefaultAllocator local = DefaultAllocatorInit();- In
Memory.c:498:
}
VecClear(&vec);
bool result = (VecLen(&vec) == 0);- In
Memory.c:510:
// once per live element.
bool test_clear_runs_deinit_once_per_element(void) {
WriteFmt("Testing VecClear invokes copy_deinit once per element\n");
DefaultAllocator local = DefaultAllocatorInit();- In
Memory.c:524:
g_deinit_calls = 0;
VecClear(&vec);
bool result = (g_deinit_calls == 3) && (VecLen(&vec) == 0);
Last updated on