SDL_stack_alloc(3)

SDL_stack_alloc3

Allocate memory on the stack (maybe).

Usage

#include "SDL3/SDL.h"

#define SDL_stack_alloc(type, count) (type*)alloca(sizeof(type)*(count))

Header file

Defined in SDL3/SDL_stdinc.h

Overview

If SDL knows how to access alloca() on the current platform, it will use it to stack-allocate memory here. If it doesn't, it will use

SDL_malloc () to heap-allocate memory.

Since this might not be stack memory at all, it's important that you check the returned pointer for NULL, and that you call

SDL_stack_free
on the memory when done with it. Since this might be stack memory, it's important that you don't allocate large amounts of it, or allocate in a loop without returning from the function, so the stack doesn't overflow.

Return value

Returns newly-allocated memory, or NULL on failure.

Thread safety

It is safe to call this macro from any thread.

Availability

This macro is available since SDL 3.2.0.

From libsdl3-doc 3.2.10+ds-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.