Function SDL_SetMemoryFunctions

pub unsafe extern "C" fn SDL_SetMemoryFunctions(
    malloc_func: Option<unsafe extern "C" fn(_: usize) -> *mut c_void>,
    calloc_func: Option<unsafe extern "C" fn(_: usize, _: usize) -> *mut c_void>,
    realloc_func: Option<unsafe extern "C" fn(_: *mut c_void, _: usize) -> *mut c_void>,
    free_func: Option<unsafe extern "C" fn(_: *mut c_void)>,
) -> bool
Available on crate feature dep_sdl3 only.
Expand description

Replace SDL’s memory allocation functions with a custom set.

It is not safe to call this function once any allocations have been made, as future calls to SDL_free will use the new allocator, even if they came from an SDL_malloc made with the old one!

If used, usually this needs to be the first call made into the SDL library, if not the very first thing done at program startup time.

§Parameters

  • malloc_func: custom malloc function.
  • calloc_func: custom calloc function.
  • realloc_func: custom realloc function.
  • free_func: custom free function.

§Return value

Returns true on success or false on failure; call [SDL_GetError()] for more information.

§Thread safety

It is safe to call this function from any thread, but one should not replace the memory functions once any allocations are made!

§Availability

This function is available since SDL 3.2.0.

§See also