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) {
    WriteFmt("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

IterRemainingSize

IterRemainingSize Description Get remaining size left to read this memory iterator.

Read More

IterRemainingLength

IterRemainingLength Description Get remaining length left to read this memory iterator.

Read More

IterLength

IterLength Description Get total length of this Iter object

Read More