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 meansmemwas resized in place, no freeing happened. iconic, no drama. - if it returns a different non-
NULLpointer, that meansmemwas freed and you absolutely cannot dereference it anymore. she's gone. moving on. π - if it returns
NULL(which means failure π), thenmemstays valid and you still have to free it withSDL_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, orNULL.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 forNULL, and never touchmemafter 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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms