littlefs-project / littlefs

A little fail-safe filesystem designed for microcontrollers
BSD 3-Clause "New" or "Revised" License
4.92k stars 774 forks source link

about defining lfs_malloc/lfs_free as macros #894

Open rahmanih opened 8 months ago

rahmanih commented 8 months ago

Hi,

lfs_malloc() and lfs_free() are currently provided as functions using the system malloc & free this prevents the LittleFS from using RTOS memory allocation like the FreeRTOS pvPortMalloc() & pvPortFree() it is possible to consider using macros instead of example

#ifndef LFS_NO_MALLOC

#ifndef lfs_malloc
#define lfs_malloc                malloc
#endif

#ifndef lfs_free
#define lfs_free                  free
#endif

#endif

regards Haithem.

geky commented 7 months ago

Hi @rahmanih, it is currently possible to override lfs_malloc/lfs_free by providing your own lfs_utils.h:

https://github.com/littlefs-project/littlefs/blob/c733d9ec5776dfc949ec6dc71fa9ce3ff71de6e5/lfs_util.h#L11-L21

Though I've come to realize this is unnecessarily cumbersome for many util overrides, and having simple ifdefs as you mentioned would be better. It's something on my TODO list. There is some other config-related work I was batching it up with which is why I haven't gotten to it yet.

geky commented 6 months ago

Improving things over here: https://github.com/littlefs-project/littlefs/pull/909

Let me know if anything looks wrong.