https://github.com/federicoponzi/libsmalloc
A custom malloc implementation
https://github.com/federicoponzi/libsmalloc
Last synced: about 1 month ago
JSON representation
A custom malloc implementation
- Host: GitHub
- URL: https://github.com/federicoponzi/libsmalloc
- Owner: FedericoPonzi
- Created: 2022-05-31T17:09:42.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-07T22:56:54.000Z (about 3 years ago)
- Last Synced: 2025-09-02T13:56:20.802Z (11 months ago)
- Language: Rust
- Size: 12.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# libsmalloc
A simple malloc (free, realloc, calloc) implementation in Rust.
```
# Test it as:
cargo build && LD_PRELOAD=$(readlink -f target/debug/libsmalloc.so) ls
```
## TODO:
* Fix thread-safety
* defer allocations larger than a page size to mmap
* set errno on failure.
* allocate more space (bigger sbrk) in advance.
* Dellocate memory on free if possible.
*
----
# C tests
I've also included some small c programs to test the behaviours. Nothing fancy, I run them like this:
```
(cd ../ && cargo build ) && gcc malloc.c && LD_PRELOAD=$(readlink -f ../target/debug/libsmalloc.so) ./a.out
# run all:
(cd ../ && cargo build )
for i in *.c ; do
gcc $i && LD_PRELOAD=$(readlink -f ../target/debug/libsmalloc.so) ./a.out
echo "----------"
done
```