VecInitAlignedWithDeepCopy
- Macro
- August 22, 2025
Table of Contents
VecInitAlignedWithDeepCopy
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
Name | Direction | Description |
---|---|---|
ci | in | Copy init method. |
cd | in | Copy deinit method. |
aln | in | Vector 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)
- In
Init.h:22
:
/// TAGS: Init, Vec, Length, Size, Aligned
///
#define VecInit() VecInitAlignedWithDeepCopy(NULL, NULL, 1)
///
- In
Init.h:53
:
/// TAGS: Init, Vec, Length, Size, Aligned, DeepCopy, DeepDeinit
///
#define VecInitWithDeepCopy(ci, cd) VecInitAlignedWithDeepCopy(ci, cd, 1)
///
- In
Init.h:93
:
/// TAGS: Init, Vec, Length, Size, Aligned
///
#define VecInitAligned(aln) VecInitAlignedWithDeepCopy(NULL, NULL, aln)
///
- In
Vec.Init.c:122
:
// 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
- In
Vec.Init.c:126
:
// 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