Skip to content

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)
            LOG_FATAL("buf_write_fmt: NULL out or fmtstr");
        }
        VecClear(out);
        return render_binary_fmt((Str *)out, fmtstr, argv, argc);
    }
            case VEC_CHAR_PTR_CLEAR : {
                // VecClear automatically calls char_ptr_deinit on each element
                VecClear(vec);
                break;
            }
            case VEC_STR_CLEAR : {
                // VecClear automatically calls StrDeinit on each element
                VecClear(vec);
                break;
            }
            // Memory operations
            case VEC_INT_CLEAR : {
                VecClear(vec);
                break;
            }
    
        // Test with a vector of even length
        VecClear(&vec);
        int even_values[] = {10, 20, 30, 40};
        for (int i = 0; i < 4; i++) {
    // Test VecClear function
    bool test_vec_clear(void) {
        WriteFmt("Testing VecClear\n");
    
        DefaultAllocator alloc = DefaultAllocatorInit();
    
        // Clear the vector
        VecClear(&vec);
    
        // Length should now be 0
    /// TAGS: Buf, Clear, Reuse
    ///
    #define BufClear(b)  VecClear(b)
    
    // Read-only accessors. The leading `((void)0, ...)` makes each macro a
    /// TAGS: Str, Memory, Clear
    ///
    #define StrClear(str) VecClear(str)
    
    ///
Last updated on