VecReserve

Table of Contents

VecReserve

Description

Reserve space for vector.

Parameters

NameDirectionDescription
vecin,outVector to be resized.
leninNew capacity of vector.

Success

return

Failure

Does not return

Usage example (Cross-references)

    /// FAILURE : Does not return
    ///
    #define StrReserve(str, n) VecReserve((str), (n))
    
    ///
    
    // Reserve more space than needed
    VecReserve(&vec, 100);
    
    // Add some data
    // Test VecReserve function
    bool test_vec_reserve(void) {
    printf("Testing VecReserve\n");
    
    // Create a vector of integers
    
    // Reserve space for 50 elements
    VecReserve(&vec, 50);
    
    // Capacity should now be at least 50
    
    // Reserve less space (should be a no-op)
    VecReserve(&vec, 20);
    
    // Capacity should still be at least 50
    
    // Ensure we have enough capacity to avoid reallocation during the test
    VecReserve(&vec2, vec2.length + 10);
    
    // Try inserting just one element first with fast insert
    
    // Reserve zero capacity
    VecReserve(&vec, 0);
    result = result && (vec.capacity == 0);
    
    // Make sure we have enough capacity to avoid reallocation issues
    VecReserve(&vec, 10);
    
    // Create several dummy items to populate the vector

Share :