Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom memory allocators #1074

Closed
raysan5 opened this issue Jan 16, 2020 · 8 comments
Closed

Support custom memory allocators #1074

raysan5 opened this issue Jan 16, 2020 · 8 comments
Labels
enhancement This is an improvement of some feature

Comments

@raysan5
Copy link
Owner

raysan5 commented Jan 16, 2020

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.

@raysan5 raysan5 added the enhancement This is an improvement of some feature label Jan 16, 2020
@raysan5
Copy link
Owner Author

raysan5 commented Jan 19, 2020

Reviewed some raylib allocations in commit bec4677.

@raysan5
Copy link
Owner Author

raysan5 commented Jan 19, 2020

jar_mod and jar_xm reviewed in commit d797bb3

@raysan5
Copy link
Owner Author

raysan5 commented Jan 19, 2020

rnet allocators reviewed in commit 1c4dadc. Just note this file should actually be redesigned...

@raysan5
Copy link
Owner Author

raysan5 commented Jan 19, 2020

dirent.h module reviewed in commit edc1d25.

@raysan5
Copy link
Owner Author

raysan5 commented Jan 19, 2020

glad.h module reviewd in commit cff3830. Note that this module load a bunch of extensions that are actually not required; raylib only uses a minimal subset of OpenGL. Maybe extensions loading could be restricted to used ones only...

@raysan5
Copy link
Owner Author

raysan5 commented Jan 22, 2020

cgltf.h updated in commit e932d23.

@raysan5
Copy link
Owner Author

raysan5 commented Jan 24, 2020

This issue is related to #966. Supposedly, new raylib module rmem can be used to manage ALL memory required by raylib and it's dependencies.

@raysan5 raysan5 mentioned this issue Jan 28, 2020
3 tasks
raysan5 added a commit that referenced this issue Mar 17, 2020
NOTE: Two libraries still use custom allocators: glfw and stb_vorbis
@raysan5
Copy link
Owner Author

raysan5 commented Mar 25, 2020

stb_vorbis implement custom memory allocation mechanisms based on malloc()/alloc()/free().

glfw just removed cutom allocators option and relies primary on calloc()/free().

I can not do much on my side about it at the moment... so, closing this issue.

@raysan5 raysan5 closed this as completed Mar 25, 2020
heretique pushed a commit to heretique/raylib that referenced this issue Apr 6, 2020


NOTE: Two libraries still use custom allocators: glfw and stb_vorbis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an improvement of some feature
Projects
None yet
Development

No branches or pull requests

1 participant