SDL_aligned_alloc(3)

✨ SDL_aligned_alloc(3) ✨

okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, where we talk about SDL_aligned_alloc πŸ’…


πŸŽ€ NAME πŸŽ€

SDL_aligned_alloc β€” allocate memory aligned to a specific alignment. yes queen, we're doing alignment today πŸ¦‹


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

void * SDL_aligned_alloc(size_t alignment, size_t size);

like. that's it. that's the whole vibe. go off 🫢


πŸ’– DESCRIPTION πŸ’–

okay so real talk, the memory this function hands you? you must free it with SDL_aligned_free(), and not SDL_free(). not a drill. NOT SDL_free(). i'm literally begging you πŸ™ˆ that's the number one way people mess this up and it's giving chaos.

if alignment is smaller than the size of void *, it gets bumped up to match that. so it's never gonna be smaller than a pointer, no cap. lowkey a little self-care on its part ✨

and here's the cute part: the returned memory address will be a multiple of the alignment value, and the size of the memory allocated will also be a multiple of the alignment value. both. iconic behaviour fr fr πŸ‘‘


🌈 FUNCTION PARAMETERS 🌈

  • alignment β€” the alignment of the memory. this is your moment, your main character number, the thing the address has to divide by evenly πŸ’«
  • size β€” the size to allocate. how much memory you want, bestie. your whole snack order πŸ“

⭐ RETURN VALUE ⭐

returns a pointer to the aligned memory, or NULL if allocation failed 😭

NULL means it didn't work. don't dereference it. don't be that girl. check your return values, periodt.

🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. any of them. all of them. the whole group chat can show up at once and it's fine πŸ’œπŸ”₯


πŸ‘‘ AVAILABILITY πŸ‘‘

this function is available since SDL 3.2.0. if you're on something older, sorry babes, it's not there yet πŸ’€


πŸ¦‹ SEE ALSO πŸ¦‹

  • SDL_aligned_free(3) β€” the one you actually have to use to free this. the way that they're a matched set… obsessed πŸ’–

and that's the whole page!! brought to you by Simple Directmedia Layer, version SDL 3.4.18 β€” mwah, slay, go allocate responsibly, ily, bye!! πŸŽ€βœ¨πŸŒΈπŸ«Ά

πŸ“¦ where this page comes from