VecInitAligned

Table of Contents

VecInitAligned

Description

Initialize vector with given alignment. It is mandatory to initialize vectors before use. Not doing so is undefined behaviour. Provided alignment is used to keep all objects at an aligned memory location, avoiding UB in some cases. It’s recommended to use aligned vector when dealing with structs containing unions.

Parameters

NameDirectionDescription
alninVector element alignment. All items will be stored by respecting the alignment boundary.

Usage example (from documentation)

  Vec(Node) nodes = VecInitAligned(16);

Usage example (Cross-references)

    // Test with a vector with alignment > 1
    typedef Vec(int) AlignedIntVec;
    AlignedIntVec aligned_vec = VecInitAligned(8);
    
    // Add some data
    // Create a vector with 8-byte alignment
    typedef Vec(int) AlignedIntVec;
    AlignedIntVec aligned_vec = VecInitAligned(8);
    
    // For 8-byte alignment, each int (4 bytes) should be padded to 8 bytes
    // Test aligned vector initialization
    bool test_vec_init_aligned(void) {
    printf("Testing VecInitAligned\n");
    
    // Test with int type and 4-byte alignment
    // Test with int type and 4-byte alignment
    typedef Vec(int) IntVec;
    IntVec vec = VecInitAligned(4);
    
    // Check initial state
    // Test with struct type and 16-byte alignment
    typedef Vec(TestItem) TestVec;
    TestVec test_vec = VecInitAligned(16);
    
    // Check initial state

Share :

Related Posts

VecInitWithDeepCopyT

VecInitWithDeepCopyT Description Initialize given vector. Default alignment is 1 It is mandatory to initialize vectors before use. Not doing so is undefined behaviour.

Read More

Vec

Vec Description Typesafe vector definition. This is much like C++ template std::vector

Read More

VecInitWithDeepCopy

VecInitWithDeepCopy Description Initialize vector. Default alignment is 1 It is mandatory to initialize vectors before use. Not doing so is undefined behaviour.

Read More