https://github.com/winterrdog/mm-allocator
a simple memory allocator written in pure C with reimplementations of malloc,calloc,realloc and free using singly linked lists. inspired by https://github.com/arjun024/memalloc
https://github.com/winterrdog/mm-allocator
Last synced: 10 months ago
JSON representation
a simple memory allocator written in pure C with reimplementations of malloc,calloc,realloc and free using singly linked lists. inspired by https://github.com/arjun024/memalloc
- Host: GitHub
- URL: https://github.com/winterrdog/mm-allocator
- Owner: winterrdog
- License: mit
- Created: 2024-04-14T08:47:58.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-21T18:40:41.000Z (over 1 year ago)
- Last Synced: 2025-01-26T09:27:20.790Z (12 months ago)
- Language: C
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mm-allocator
a simple memory allocator written in pure C with reimplementations of `malloc`,`calloc`,`realloc` and `free` using _singly linked lists_
## How to use
1. Clone the repository
2. Compile the source code using the following command
```bash
bash compile.sh
```
3. Run the compiled executable. I'll test it with the `ls` command
```bash
LD_PRELOAD=./mm.so /usr/bin/ls # or just ls or any other program
```
The way this works is that the `LD_PRELOAD` environment variable is used to load the shared library `mm.so` before the `ls` command is executed. This will cause the `malloc`, `calloc`, `realloc` and `free` functions to be redirected to the ones in our custom memory allocator. By default, `LD_PRELOAD` points to the standard C library, so we are essentially replacing the standard memory allocation functions with our custom ones.
You can see it in action [here](https://asciinema.org/a/gsY8AQNKLgzAmSdu7F1f24kdT)
## NOTE
This program is quite limited in functionality and is not meant to be used in production. It is just a simple demonstration of how memory allocation works under the hood. The program is not thread-safe and does not handle memory fragmentation. It is just a simple implementation to understand the basic concepts of memory allocation. Therefore it can seriously segfault if used inappropriately.