VecInitAlignedStack

Table of Contents

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

NameDirectionDescription
vin,outVector that needs to be initialized.
neinNumber of elements to allocate aligned stack memory for.
alninAlignment 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.

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

VecInitAlignedWithDeepCopyStack

VecInitAlignedWithDeepCopyStack 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…

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