CARB_STACK_ALLOC

Defined in carb/Defines.h

CARB_STACK_ALLOC(T, number)

Attempts to allocate an array of the given type on the stack.

Note

The memory allocated is within the stack frame of the current function and is automatically freed when the function returns or longjmp() or siglongjmp() is called. The memory is not freed when leaving the scope that allocates it, except by the methods mentioned.

Warning

On Windows, the underlying call to _alloca() may throw a SEH stack overflow exception if the stack does not have sufficent space to perform the allocation. However, on Linux, there is no error handling for the underlying alloca() call. The caller is advised to use caution.

Parameters
  • T – The type of the object(s) to allocate.

  • number – The number of objects to allocate. If 0, a nullptr is returned.

Returns

A properly-aligned pointer that will fit number quantity of type T on the stack. This memory will be freed automatically when the function returns or longjmp() or siglongjmp() is called.