SDL_malloc_func(3type)

πŸ’– SDL_malloc_func πŸ’–

okay bestie, welcome to the SDL_malloc_func page, part of the SDL3 datatypes era, and honestly? this one's short and sweet and kinda iconic for it. no cap.


✨ NAME ✨

SDL_malloc_func β€” it's a callback, and its whole job is to be the thing that actually implements SDL_malloc(). like, SDL's malloc is calling you up and being like "hey, you handle the memory, i trust you." main character energy fr fr. πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

typedef void *(SDLCALL *SDL_malloc_func)(size_t size);

look at that little typedef. precious. it takes a size_t size and hands back a void *, and there's a SDLCALL in there because calling conventions are a thing we respect in this house. πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

SDL is gonna be super considerate about this, okay? SDL will always ensure that the passed size is greater than 0. so you never have to sit there wondering "what if they ask me to allocate zero bytes" β€” they won't. the size is always gonna be a positive number. that's the vibe. ✨


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • size β€” the size to allocate. that's it, that's the whole thing. the amount of memory you're being asked to hand over. πŸ’–

πŸ’œ RETURN VALUE πŸ’œ

you return a pointer to the allocated memory. and if the allocation flops? you return NULL. no drama, just NULL, and SDL will deal with it. 😭


πŸ”₯ THREAD SAFETY πŸ”₯

It should be safe to call this callback from any thread. so like, any thread can roll up and call you, and that's fine and expected. go off, multithreading queen. πŸ‘‘


⭐ AVAILABILITY ⭐

this datatype has been around since SDL 3.2.0. so if you're on 3.2.0 or later, you're golden. ✨


🌈 SEE ALSO 🌈

go read those too, bestie, they're all part of the same memory-functions friend group. iykyk. 🫢


lowkey reminder: this is just a typedef, not a function you call directly β€” it's the shape of a callback you'd write yourself and hand to SDL. don't @ me. πŸ’…

and that's the page!! brought to you by Simple Directmedia Layer, from the SDL 3.4.18 era, and this lil entry is SDL_malloc_func(3type). mwah, go allocate something cute. πŸ“πŸ§šπŸŒΈ

πŸ“¦ where this page comes from