Skip to content

VecSize

Description

Total used storage in bytes (aligned element size times length). Use this rather than sizeof(element) * length because vector elements may be padded for alignment.

Parameters

Name Direction Description
v in Vector to query.

Usage example (Cross-references)

Usage examples (Cross-references)
    
            case VEC_CHAR_PTR_SIZE : {
                size_t size_bytes = VecSize(vec);
                (void)size_bytes; // Use the result to avoid warnings
                break;
    
            case VEC_STR_SIZE : {
                size_t size_bytes = VecSize(vec);
                (void)size_bytes; // Use the result to avoid warnings
                break;
    
            case VEC_INT_SIZE : {
                volatile uint64_t size_val = VecSize(vec);
                (void)size_val;
                break;
    
        // Check that end - begin equals the size of the vector
        size vec_size = VecSize(&vec);
        result        = result && ((end - (char *)begin) == vec_size);
    // Test VecSize and VecLen functions
    bool test_vec_size_len(void) {
        WriteFmt("Testing VecSize and VecLen\n");
    
        DefaultAllocator alloc    = DefaultAllocatorInit();
    
        // Check initial size and length
        size vec_size = VecSize(&vec);
        size vec_len  = VecLen(&vec);
        bool result   = (vec_size == 0);
    
        // Check size and length after adding elements
        vec_size            = VecSize(&vec);
        vec_len             = VecLen(&vec);
        size aligned_offset = VecAlignedOffsetAt(&vec, VecLen(&vec));
    
        // Check size and length with alignment
        size aligned_vec_size  = VecSize(&aligned_vec);
        size aligned_vec_len   = VecLen(&aligned_vec);
        size aligned_offset_at = VecAlignedOffsetAt(&aligned_vec, VecLen(&aligned_vec));
    /// TAGS: Str, Access, Size, Bytes
    ///
    #define StrSize(str) VecSize(str)
    
    ///
Last updated on