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()
orsiglongjmp()
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 sufficient space to perform the allocation. However, on Linux, there is no error handling for the underlyingalloca()
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
, anullptr
is returned.
- Returns
A properly-aligned pointer that will fit
number
quantity of typeT
on the stack. This memory will be freed automatically when the function returns orlongjmp()
orsiglongjmp()
is called.