Skip to content

Support custom memory allocators  #1074

@raysan5

Description

@raysan5

raylib implements RL_MALLOC, RL_CALLOC, RL_REALLOC and RL_FREE but some of the external libraries implement their own memory allocators definitions, others none at all.

Below table shows allocators used by external libraries used by raylib, all of them should be custom allocators to have full control over raylib programs memory allocation if it was required, for example on embedded devices.

library custom alloc custom free others state
glfw calloc() free() realloc() ❗️
glad - GLAD_FREE GLAD_REALLOC ✔️
miniaudio MA_MALLOC MA_FREE MA_REALLOC ✔️
stb_image STBI_MALLOC STBI_FREE STBI_REALLOC, STBI_REALLOC_SIZED ✔️
stb_image_write STBIW_MALLOC STBIW_FREE STBIW_REALLOC, STBIW_REALLOC_SIZED ✔️
stb_image_resize STBIR_MALLOC STBIR_FREE ✔️
stb_vorbis malloc() free() ❗️
dr_flac DRFLAC_MALLOC DRFLAC_FREE DRFLAC_REALLOC ✔️
dr_mp3 DRMP3_MALLOC DRMP3_FREE DRMP3_REALLOC ✔️
dr_wav DRWAV_MALLOC DRWAV_FREE DRWAV_REALLOC ✔️
jar_mod JARMOD_MALLOC JARMOD_FREE ✔️
jar_xm JARXM_MALLOC JARXM_FREE ✔️
par_shapes PAR_MALLOC PAR_FREE PAR_CALLOC ✔️
cgltf CGLTF_MALLOC CGLTF_FREE ✔️
dirent DIRENT_MALLOC DIRENT_FREE ✔️
rgif RGIF_MALLOC RGIF_FREE ✔️
tinyobj_loader_c TINYOBJ_MALLOC TINYOBJ_FREE TINYOBJ_REALLOC, TINYOBJ_CALLOC ✔️

NOTE: stb_vorbis and glfw implement custom allocators mechanism based on functions pointers... but it will be nice to be able to also re-define default allocators.

Below table shows allocators used by raylib modules.

raylib module custom alloc custom free others state
core RL_MALLOC RL_FREE ✔️
rlgl RL_MALLOC RL_FREE RL_CALLOC, RL_REALLOC ✔️
text RL_MALLOC RL_FREE RL_CALLOC, RL_REALLOC ✔️
textures RL_MALLOC RL_FREE RL_REALLOC ✔️
physac PHYSAC_MALLOC PHYSAC_FREE ✔️
rnet RNET_MALLOC RNET_FREE RNET_CALLOC ✔️
rmem malloc() free() ✔️

Note that all libraries custom allocators should ultimatelly fallback to raylib allocators: RL_MALLOC, RL_CALLOC, RL_REALLOC, RL_FREE.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementThis is an improvement of some feature

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions