Skip to content

Implement AllocRef on System without GlobalAlloc #43

New issue

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

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

Already on GitHub? # to your account

Open
TimDiekmann opened this issue Mar 6, 2020 · 3 comments
Open

Implement AllocRef on System without GlobalAlloc #43

TimDiekmann opened this issue Mar 6, 2020 · 3 comments
Labels
A-Traits Other traits beside the Alloc trait Proposal

Comments

@TimDiekmann
Copy link
Member

TimDiekmann commented Mar 6, 2020

Currently, System as AllocRef calls the GlobalAlloc implementation. GlobalAlloc for System is implemented in std::sys::*::alloc.
I'd like to swap this for two reasons:

  • AllocRef has more methods like grow_in_place. At least dlmalloc supports this.
  • By name, System makes more sense to be implemented in std::sys::*::alloc.
@TimDiekmann TimDiekmann added A-Traits Other traits beside the Alloc trait Proposal labels Mar 6, 2020
@TimDiekmann
Copy link
Member Author

Some notes on ZST handling for used allocators in std:

  • hermit: Returns 0 on zero-sized allocations
  • Windows: Using HeapAlloc. Documentation does not mention, how it behaves on zero-sized allocation.
  • WASM/sgx: Uses dlmalloc:

    Even a request for zero bytes (i.e., malloc(0)) returns a pointer to something of the minimum allocatable size [...] typically 4096 or 8192 bytes.

  • CloudABI/Unix/VXWorks/WASI: Uses malloc-like API, implementation defined

So supporting ZST will not change anything, we have to check for ZSTs ourself.

@Amanieu
Copy link
Member

Amanieu commented Mar 7, 2020

As an end-goal, I think we will want to completely replace GlobalAlloc with AllocRef (i.e. #[global_allocator] requires AllocRef instead of GlobalAlloc). This is discussed in more detail in #21. As part of this we will provide a "compatibility wrapper" of impl AllocRef for T where T: GlobalAlloc which implements AllocRef using the GlobalAlloc methods.

So basically, I am in favor of this change since it moves us towards the direction of AllocRef being the "primary" implementation for System.

@TimDiekmann
Copy link
Member Author

I think that we should wait with this change until #38, #41, and #42 are merged (I expect this), otherwise I have to change many files on every push. Falling back to GlobalAlloc is currently quiet convenient.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-Traits Other traits beside the Alloc trait Proposal
Projects
None yet
Development

No branches or pull requests

2 participants