https://github.com/gcarq/collam
A naive and thread safe general-purpose allocator written in Rust built with #[no_std].
https://github.com/gcarq/collam
allocator rust
Last synced: 21 days ago
JSON representation
A naive and thread safe general-purpose allocator written in Rust built with #[no_std].
- Host: GitHub
- URL: https://github.com/gcarq/collam
- Owner: gcarq
- Created: 2019-12-19T21:17:57.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-29T14:47:15.000Z (almost 2 years ago)
- Last Synced: 2025-04-11T00:45:57.409Z (21 days ago)
- Topics: allocator, rust
- Language: Rust
- Size: 191 KB
- Stars: 13
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# collam
[](https://travis-ci.org/gcarq/collam) [](https://coveralls.io/github/gcarq/collam?branch=master)A naive and thread safe general-purpose allocator written in Rust built with `#[no_std]`.
This project started as an experiment to get comfortable with `#[no_std]` environments and `unsafe` Rust.
This library is currently *NOT* stable and I'm sure there are plenty of bugs, be warned!## A note on its state
Collam implements the `GlobalAlloc` trait and can be used within Rust.
The sub-crate `posix` exposes `malloc`, `calloc`, `realloc`, `free`, `malloc_usable_size`, `mallopt` and can be used for arbitrary programs,
in its current state its working with almost all tested programs using `LD_PRELOAD`.## Tested platforms
[x] Linux x86_64## Implementation details
Bookkeeping is currently done with an intrusive doubly linked list.
The overhead for each use allocated block is 16 bytes whereas only 12 bytes of them are used.## Performance
In regards of memory usage/overhead it is comparable to dlmalloc with tested applications,
however the performance is not there yet.## Usage within Rust
```rust
use collam::alloc::Collam;#[global_allocator]
static ALLOC: Collam = Collam::new();fn main() {
let mut vec = Vec::new();
vec.push(42);
assert_eq!(vec.pop().unwrap(), 42);
}
```## Testing collam in C/POSIX environment
Make sure you have Rust nightly.
Manually overwrite default allocator:
```bash
$ cargo build --manifest-path posix/Cargo.toml --release
$ LD_PRELOAD="$(pwd)/posix/target/release/libcollam.so" kwrite
```
Or use the test script in the root folder:
```bash
$ ./scripts/test.sh kwrite
```
There are some more helper scripts for debugging, profiling, etc. See `scripts/` folder.## Execute tests
Tests are not thread safe, make sure to force 1 thread only!
```bash
$ cargo test --all-features -- --test-threads 1
```## TODO:
* Proper Page handling
* mmap support
* Thread-local allocation
* Logarithmic-time complexity allocation
* Support for different architectures
* Proper logging