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

Expose Rust Global Allocator to LVGL C code #49

Open
rafaelcaricio opened this issue May 26, 2021 · 2 comments
Open

Expose Rust Global Allocator to LVGL C code #49

rafaelcaricio opened this issue May 26, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@rafaelcaricio
Copy link
Collaborator

We could enable the LVGL side to use Rust memory allocator, if it's available and the feature "alloc" enabled in lvgl-rs. That way we wouldn't need to use our custom Box implementation for that case. We would still need this implementation for cases where all features in lvgl-rs are disabled and we do not have a Box abstraction to handover memory to LVGL C.

Some code example of how this could work is available at: https://github.com/ezrosent/allocators-rs/tree/master/malloc-bind
We could get inspiration from the malloc-bind project and implement a similar solution to be used in embedded devices.

The problem we want to solve is that LVGL C always support "dynamically" allocated memory backed by a static array-based backend, just like wee_alloc. LVGL-rs is a library and the choice of allocator must be made by the firmware/application developer. Besides that, the developer might decide that they don't want to have an allocator at all on their Rust firmware. LVGL C will still use their own memory management implementation.

One option is to always require users of LVGL-rs to define a global allocator in their project. This would be a limitation for some use cases?! In that scenario, we wouldn't need the code in mem module at all, since the memory space would be shared by LVGL C and Rust.

@rafaelcaricio
Copy link
Collaborator Author

On this topic, this is a very interesting option to consider using in LVGL-rs and recommending to users:

This allows to handle allocation errors when using collections.

@rafaelcaricio
Copy link
Collaborator Author

There is an ongoing support in Rust for explicit allocator usage, this could help support the use of the LVGL internal allocator through lvgl-rs.

Example API: https://doc.rust-lang.org/alloc/boxed/struct.Box.html#method.new_in

@nia-e nia-e added the enhancement New feature or request label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants