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)

    // Test vector initialization with alignment and deep copy functions
    bool test_vec_init_aligned_with_deep_copy(void) {
    WriteFmt("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
    /// 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)
    
    ///
    
    #ifdef __cplusplus
    #    define VecInitAlignedWithDeepCopyT(v, ci, cd, aln) (TYPE_OF(v) VecInitAlignedWithDeepCopy((ci), (cd), (aln)))
    #else
    ///
    /// TAGS: Init, Vec, Length, Size, Aligned, DeepCopy, DeepDeinit
    ///
    #    define VecInitAlignedWithDeepCopyT(v, ci, cd, aln) ((TYPE_OF(v))VecInitAlignedWithDeepCopy((ci), (cd), (aln)))
    #endif

Share :

Related Posts

IterSize

IterSize Description Get total size of this Iter object

Read More

IterRemainingSize

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

Read More

VecInitAlignedT

VecInitAlignedT Description Initialize given 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.

Read More