SDL_memcpy(3)

πŸ’– SDL_memcpy β€” SDL3 FUNCTIONS πŸ’–

okay bestie, gather round, because we're about to talk about the most "copy and paste but make it C" function in the whole SDL3 lineup 🫢

✨ NAME ✨

SDL_memcpy β€” copy non-overlapping memory. that's it. that's the whole job. she copies bytes and she does NOT want drama πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

void * SDL_memcpy(void *dst, const void *src, size_t len);

πŸ¦‹ DESCRIPTION πŸ¦‹

so here's the tea, and it is IMPORTANT tea: the memory regions must not overlap. like, at all. not even a little. if they do overlap, do not pass go, do not collect $200 β€” go use SDL_memmove() instead, because she was literally built for that πŸ’€

lowkey a vibe check: overlapping + SDL_memcpy = undefined behaviour territory. SDL_memmove() is your girl for that situation, fr fr.

πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • dst β€” the destination memory region. she must not be NULL, and she must not overlap with src. boundaries, queen πŸ‘‘
  • src β€” the source memory region. same rules, bestie: must not be NULL, and must not overlap with dst.
  • len β€” the length in bytes of both dst and src. one number, two regions, equal treatment, we love to see it ✨

πŸ’œ RETURN VALUE πŸ’œ

returns dst. that's it. she gives you back exactly what you handed her. iconic behaviour honestly 🌈


🌟 THREAD SAFETY 🌟

it is safe to call this function from any thread. go wild, multi-threaded besties, she's not gonna snitch 🧚


⭐ AVAILABILITY ⭐

this function is available since SDL 3.2.0. so if you're on something older… girl. upgrade 😭


πŸ‘‘ SEE ALSO πŸ‘‘

  • SDL_memmove(3) β€” the overlapping-safe sister. when in doubt, she's the one you text 🫢

and that's the whole page, bestie!! this lil masterpiece came to you courtesy of Simple Directmedia Layer, version SDL 3.4.18 πŸ’– now go copy some non-overlapping bytes and slay βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from