---
name: "SDL_stack_alloc"
section: "3"
platform: "linux"
package: "libsdl3-doc"
version: "3.2.10+ds-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/SDL_stack_alloc"
---

# SDL\_stack\_alloc(3)

Allocate memory on the stack (maybe).

## NAME

SDL\_stack\_alloc - Allocate memory on the stack (maybe).

## HEADER FILE

Defined in SDL3/SDL\_stdinc.h

## SYNOPSIS

```
#include "SDL3/SDL.h"
```

**#define SDL\_stack\_alloc(type, count)    (type\*)alloca(sizeof(type)\*(count))**

## DESCRIPTION

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.

## SEE ALSO

**•**(3), **SDL\_stack\_free**(3)
