SDL_TLSDESTRUCTORCALLBACK(3type)

πŸ’– SDL_TLSDestructorCallback πŸ’–

okay bestie, welcome to the SDL3 DATATYPES corner of the manual, where we talk about SDL_TLSDestructorCallback β€” yes that's a whole mouthful, no I will not be pronouncing it out loud, and yes it is genuinely iconic once you get what it does 🫢


✨ NAME ✨

SDL_TLSDestructorCallback β€” the callback used to cleanup data passed to SDL_SetTLS.

like. it's the lil cleanup crew. the one that shows up when a thread dips out and makes sure nothing's left lying around 🧹✨


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_thread.h>

typedef void (SDLCALL *SDL_TLSDestructorCallback)(void *value);

that's it. that's the whole thing. a function pointer type, slaying quietly πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the vibe: this callback gets called when a thread exits, and its whole job is to let an app free any resources it was holding onto. it's giving responsible bestie energy β€” you made a mess in that thread, and now somebody's gotta clean it up before the lights go out 😭

it's literally just there so you don't leak stuff when a thread says bye. periodt.


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • value β€” a pointer previously handed to SDL_SetTLS. like, the exact same pointer you gave it. it comes back to you one last time so you can free it πŸ’€

🌈 AVAILABILITY 🌈

this datatype is available since SDL 3.2.0. so if you're on anything older than that... bestie, it's not there, sorry πŸ™ˆ


πŸ‘‘ SEE ALSO πŸ‘‘


ngl, if you're reading this because you're writing a destructor and you're not sure when it fires: it fires on thread exit. that's the whole moment. don't overthink it πŸ’œ

okay that's the page!! go forth and free your memory!! πŸ“πŸ’–βœ¨

β€” written with love for Simple Directmedia Layer, SDL 3.4.18. mwah. πŸ’…πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from