SDL_ALLOC_SIZE(3)

✨ SDL_ALLOC_SIZE ✨

okay bestie, welcome to the SDL_ALLOC_SIZE page, a macro from the SDL3 functions family that tags a function as returning a certain allocation πŸ’–


πŸŽ€ NAME πŸŽ€

SDL_ALLOC_SIZE β€” a macro that tags a function as returning a certain allocation πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_begin_code.h>

#define SDL_ALLOC_SIZE(p) __attribute__((alloc_size(p)))

πŸ¦‹ DESCRIPTION πŸ¦‹

so what does this actually do? it's a hint to the compiler that a function allocates and returns a specific amount of memory, and that the amount is based on one of its arguments. that's it. that's the whole vibe. ✨

like, picture the C runtime's malloc() function. it could totally use this macro with an argument of 1, because the first argument to malloc is the size of the allocation. iconic behavior, honestly πŸ‘‘

on compilers that don't have alloc_size support, this macro is defined to nothing. so it just... evaporates. no drama, no errors, just vibes 🫢

⚠️ real talk though: most apps don't need to use this directly, and should not use it directly. it's giving internal-tool energy. leave it to the library, bestie 😭

🌈 AVAILABILITY 🌈

this macro has been available since SDL 3.2.0. periodt πŸ’œ


and that's the whole page, no cap 🌸 brought to you by Simple Directmedia Layer, SDL 3.4.18, mwah πŸ’‹ go forth and let the compiler cook πŸ“

πŸ“¦ where this page comes from