Skip to content

Add the simplest heap #107

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

JalonWong
Copy link

A simplest heap is very useful on a resource-constrained platform and avoids the need to use heapless modules. Its usage is the same as other heaps.
Because it's the simplest implementation, it doesn't free memory. Any memory you drop cannot be reused (it's leaked), so avoid dropping anything whenever possible.

@JalonWong JalonWong requested a review from a team as a code owner August 17, 2025 04:56
@zeenix
Copy link

zeenix commented Aug 17, 2025

Thanks you for adding a description to the PR.

Because it's the simplest implementation, it doesn't free memory.

It would be good to have an example use case here, where the existing impls would not be a good fit but this simplest impl would be better fit.

Any memory you drop cannot be reused (it's leaked), so avoid dropping anything whenever possible.

That seems like footgun and unsound behaviour to me. The example use case description should also document why this is worth having.

@zeenix
Copy link

zeenix commented Aug 17, 2025

Because it's the simplest implementation, it doesn't free memory.

It would be good to have an example use case here, where the existing impls would not be a good fit but this simplest impl would be better fit.

This is keeping in mind that the API remains almost identical to the user, they only have to pick one of the impls.

Cargo.toml Outdated
@@ -24,13 +24,15 @@ name = "embedded-alloc"
version = "0.6.0"

[features]
default = ["llff", "tlsf"]
default = ["llff", "tlsf", "simplest"]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we go forward with this new feature, IMO it should not be the default.

@JalonWong
Copy link
Author

JalonWong commented Aug 18, 2025

Because it's the simplest implementation, it doesn't free memory.

It would be good to have an example use case here, where the existing impls would not be a good fit but this simplest impl would be better fit.

@zeenix
I'm not sure what kind of example use case I can write. In some very small systems people just new instances and don't drop anything. Actually llff is good enough for most situations, which is similar to the heap4 in FreeRTOS. And this one is similar to the heap1 in the FreeRTOS. You only need it in a extreme situation.

You are right, this implementation is unsound, so I'm not sure if it's good to merge it into this crate. Maybe I can keep it private.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants