VecInitAlignedWithDeepCopy

Table of Contents

VecInitAlignedWithDeepCopy

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
ciinCopy init method.
cdinCopy deinit method.
alninVector element alignment. All items will be stored by respecting the alignment boundary.

Usage example (from documentation)

  typedef Vec(Node) NodeVec;
  NodeVec nodes = VecInitAlignedWithDeepCopy(NodeInitCopy, NodeDeinit, 48);

Usage example (Cross-references)

    /// TAGS: Init, Vec, Length, Size, Aligned
    ///
    #define VecInit() VecInitAlignedWithDeepCopy(NULL, NULL, 1)
    
    ///
    /// TAGS: Init, Vec, Length, Size, Aligned, DeepCopy, DeepDeinit
    ///
    #define VecInitWithDeepCopy(ci, cd) VecInitAlignedWithDeepCopy(ci, cd, 1)
    
    ///
    /// TAGS: Init, Vec, Length, Size, Aligned
    ///
    #define VecInitAligned(aln) VecInitAlignedWithDeepCopy(NULL, NULL, aln)
    
    ///
    // Test vector initialization with alignment and deep copy functions
    bool test_vec_init_aligned_with_deep_copy(void) {
    printf("Testing VecInitAlignedWithDeepCopy\n");
    
    // Test with struct type, custom copy/deinit functions, and 8-byte alignment
    // Test with struct type, custom copy/deinit functions, and 8-byte alignment
    typedef Vec(TestItem) TestVec;
    TestVec vec = VecInitAlignedWithDeepCopy(TestItemCopyInit, TestItemDeinit, 8);
    
    // Check initial state

Share :

Related Posts

VecInitT

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

Read More

VecInit

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

Read More

BitVecLen

BitVecLen Description Get number of bits currently in bitvector.

Read More