VecInitAlignedStack
- Macro
- August 22, 2025
Table of Contents
VecInitAlignedStack
VecInitAlignedStack
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. These vectors are best used where user doesn’t get a chance to or does not want to deinit vector, given that no data in vector needs to be deinitialized. Example includes, but does not limit to a Vec(i8), Vec(f32), etc…
Parameters
Name | Direction | Description |
---|---|---|
v | in,out | Vector that needs to be initialized. |
ne | in | Number of elements to allocate aligned stack memory for. |
aln | in | Alignment value to align all emenets to. |
Usage example (from documentation)
Vec(Node*) nodes;
// initialize vector with stack memory, aligned with 124 byte boundary
VecInitAlignedStack(&nodes, 24, 124, {
// scope where vector memory is available
FindAndFillAllNodes(&nodes, ... /* some other relevant data */);
UseNodes(&nodes);
VecForeach(&nodes, node, {
DestroyNode(node);
});
// vector deinit will be called for you after this automatically
// so any data held by the vector in this scope is invalid outside
});
Usage example (Cross-references)
No external code usages found in the scanned files.