SDL_realloc(3)

✨ SDL_realloc(3) ✨

okay bestie, welcome to the SDL3 FUNCTIONS corner of the man pages, and today's main character is SDL_realloc β€” she resizes your memory for you πŸ’…


🌸 NAME 🌸

SDL_realloc β€” Change the size of allocated memory.


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_stdinc.h>

void * SDL_realloc(void *mem, size_t size);

πŸ’– DESCRIPTION πŸ’–

so the memory that comes back from this function? yeah, you must free it with SDL_free(). no exceptions, no vibes-based cleanup, fr fr.

if size is 0, it will be set to 1. and ngl this is different from some other C runtime realloc implementations out there, which might treat realloc(mem, 0) the same way as free(mem). not us. we said size 1. periodt.

if mem is NULL, this function behaves exactly like SDL_malloc(). otherwise, bestie, you're getting one of three possible outcomes and you need to know which one you got:

  • if it returns the same pointer as mem, that means mem was resized in place, no freeing happened. iconic, no drama.
  • if it returns a different non-NULL pointer, that means mem was freed and you absolutely cannot dereference it anymore. she's gone. moving on. πŸ’€
  • if it returns NULL (which means failure 😭), then mem stays valid and you still have to free it with SDL_free(). don't forget her.

if the allocation is successfully resized, the returned pointer is guaranteed to be aligned to either the fundamental alignment (alignof(max_align_t) in C11 and later) or 2 * sizeof(void *), whichever is smaller. cute and aligned, as she should be. ✨


πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • mem β€” a pointer to allocated memory to reallocate, or NULL.
  • size β€” the new size of the memory.

🌈 RETURN VALUE 🌈

returns a pointer to the newly allocated memory, or NULL if the allocation failed. that's the whole vibe check.


🧚 THREAD SAFETY 🧚

it is safe to call this function from any thread. go off, multithreaded queen πŸ‘‘


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0.


🫢 SEE ALSO 🫢


reminder bestie: free what you allocate, check for NULL, and never touch mem after a moved pointer. that's the whole assignment πŸ’–

and that's the page!! brought to you by Simple Directmedia Layer, SDL version 3.4.18 β€” mwah, go resize something responsibly πŸŽ€βœ¨πŸ’…

πŸ“¦ where this page comes from