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

implement allocator-api via allocator-api2 crate #2192

Open
liebman opened this issue Sep 18, 2024 · 4 comments
Open

implement allocator-api via allocator-api2 crate #2192

liebman opened this issue Sep 18, 2024 · 4 comments
Labels
package:esp-alloc Issues related to the esp-alloc package

Comments

@liebman
Copy link
Contributor

liebman commented Sep 18, 2024

Motivations

Now that we have an allocator that supports multiple heaps we need to be able to choose where something is allocated.

Solution

We should consider using this crate to provides the api in a stable environment. I'll admit I've not looked deeply into this, but for some things being able to specify to allocate from psram (or NOT from psram) would be helpful.

Thoughts?

@liebman liebman added the status:needs-attention This should be prioritized label Sep 18, 2024
@MabezDev
Copy link
Member

Do you have an idea of how it might work?

Currently, we only have one allocator, so being able to specify the allocator on collections like Vec isn't that helpful. We also have the complication that we may or may not have a psram allocator, and we won't know until runtime. Maybe a psram allocator that has so psram attached is fine, it will just fail to allocate I anything I guess?

@bugadani
Copy link
Contributor

bugadani commented Sep 18, 2024

Currently, we only have one allocator

Wellactually :) If we implement the api for PSRAM, we can specify some types to be placed in PSRAM with this.

Sometimes this might come handy, not knowing until runtime may be fine in some systems.

Maybe a psram allocator that has so psram attached is fine, it will just fail to allocate I anything I guess?

Yes!

@bjoernQ
Copy link
Contributor

bjoernQ commented Sep 19, 2024

In future we might add more ways to decide from which memory we need to allocate (not sure we need it but allowed alignment, able to execute code etc. comes to my mind)

I could think of a way to get an Allocator api implementation from esp-alloc matching a given EnumSet<MemoryCapability>

@MabezDev
Copy link
Member

I think this might be as simple as:

pub struct PsramAllocator(&'static EspHeap);

pub static PSRAM_ALLOCATOR: PsramAllocator = PsramAllocator(&HEAP);

and then impl GlobalAlloc for PSRAM_ALLOCATOR which always uses MemoryCapability::External when allocating via the internal heap.

We'd probably want an example that show cases this with the allocator-api2 crate.

@MabezDev MabezDev removed the status:needs-attention This should be prioritized label Sep 23, 2024
@MabezDev MabezDev added the package:esp-alloc Issues related to the esp-alloc package label Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:esp-alloc Issues related to the esp-alloc package
Projects
Status: Todo
Development

No branches or pull requests

4 participants