Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/huonw/rust-malloc
A pure Rust memory allocator
https://github.com/huonw/rust-malloc
Last synced: 8 days ago
JSON representation
A pure Rust memory allocator
- Host: GitHub
- URL: https://github.com/huonw/rust-malloc
- Owner: huonw
- License: other
- Created: 2013-07-15T03:02:43.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-07T23:11:02.000Z (about 11 years ago)
- Last Synced: 2024-10-31T13:50:15.959Z (15 days ago)
- Language: Rust
- Size: 109 KB
- Stars: 49
- Watchers: 5
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
# Rust malloc
A pure-Rust proof-of-concept implementation of `malloc`/`free` for
x86-64 Linux. It is very, very basic: a linked list of allocations
(traversed on every `malloc` call!), first-fit strategy and all
allocations come directly from the `brk` syscall. As such, it is very
slow, not-threadsafe and generally bad. There is little-to-no error
checking.Uses a modified version of
[zero.rs](https://github.com/pcwalton/zero.rs) and a
[tiny syscall](https://gist.github.com/Aatch/5894562)
wrapper. Requires a recent `rustc` from master.There is an example of a custom version of `~T` using this allocator
at the bottom of `malloc.rs`.Test with:
make
./mallocTo enable the debugging `assert`s:
make debug
./malloc-debugCode map:
- `malloc.rs` contains `malloc`, `free`, etc, as well as `main` and some tests/examples.
- `types.rs` contains the allocation header (`Header`, surprisingly)
as well some newtype structs around raw pointers (`Box` and `Data`;
in theory these have no runtime cost over using `*mut Header` and
`*mut u8` directly) which make the implementation relatively
type-safe.
- `util.rs` & `diag.rs` contain utilities and tools for printing
diagnostics about the current allocation state.**Only useful for segfaulting and generally making programs incorrect.**
## TODO
- Use `mmap`.
- Return memory to the OS.
- Merge adjacent free cells better.### Wishlist
- Make it fast.
- Support other platforms/operating systems.