sdlSetMemoryFunctions function
- Pointer<
NativeFunction< mallocFunc,SdlMallocFunc> > - Pointer<
NativeFunction< callocFunc,SdlCallocFunc> > - Pointer<
NativeFunction< reallocFunc,SdlReallocFunc> > - Pointer<
NativeFunction< freeFunc,SdlFreeFunc> >
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.
\param malloc_func custom malloc function. \param calloc_func custom calloc function. \param realloc_func custom realloc function. \param free_func custom free function. \returns true on success or false on failure; call SDL_GetError() for more information.
\threadsafety It is safe to call this function from any thread, but one should not replace the memory functions once any allocations are made!
\since This function is available since SDL 3.1.3.
\sa SDL_GetMemoryFunctions \sa SDL_GetOriginalMemoryFunctions
extern SDL_DECLSPEC bool SDLCALL SDL_SetMemoryFunctions(SDL_malloc_func malloc_func, SDL_calloc_func calloc_func, SDL_realloc_func realloc_func, SDL_free_func free_func)
Implementation
bool sdlSetMemoryFunctions(
Pointer<NativeFunction<SdlMallocFunc>> mallocFunc,
Pointer<NativeFunction<SdlCallocFunc>> callocFunc,
Pointer<NativeFunction<SdlReallocFunc>> reallocFunc,
Pointer<NativeFunction<SdlFreeFunc>> freeFunc) {
final sdlSetMemoryFunctionsLookupFunction = libSdl3.lookupFunction<
Uint8 Function(
Pointer<NativeFunction<SdlMallocFunc>> mallocFunc,
Pointer<NativeFunction<SdlCallocFunc>> callocFunc,
Pointer<NativeFunction<SdlReallocFunc>> reallocFunc,
Pointer<NativeFunction<SdlFreeFunc>> freeFunc),
int Function(
Pointer<NativeFunction<SdlMallocFunc>> mallocFunc,
Pointer<NativeFunction<SdlCallocFunc>> callocFunc,
Pointer<NativeFunction<SdlReallocFunc>> reallocFunc,
Pointer<NativeFunction<SdlFreeFunc>> freeFunc)>(
'SDL_SetMemoryFunctions');
return sdlSetMemoryFunctionsLookupFunction(
mallocFunc, callocFunc, reallocFunc, freeFunc) ==
1;
}