Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/harshitv21/memory-allocator-in-c
A basic implementation of memory allocation using C.
https://github.com/harshitv21/memory-allocator-in-c
Last synced: 3 days ago
JSON representation
A basic implementation of memory allocation using C.
- Host: GitHub
- URL: https://github.com/harshitv21/memory-allocator-in-c
- Owner: Harshitv21
- Created: 2023-10-03T15:16:19.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-03T16:16:17.000Z (about 1 year ago)
- Last Synced: 2023-10-04T14:13:50.594Z (about 1 year ago)
- Language: C
- Size: 1.6 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Memory Allocator in C
The goal of this project was to implement a pretty basic memory allocator to better understand the memory allocation by writting our own `malloc()`, `calloc()`, `realloc()` and `free()`.
By implementing these functions on our own we will be able to understand the intuition behind the working of these functions.## Docs
A step-by-step beginner friendly guide can be found [here](https://github.com/Harshitv21/Memory-Allocator-In-C/blob/main/Docs/Memory%20Allocator.md) for anyone who wants to implement or try it for yourself.
Source code for this project can be found [here](https://github.com/Harshitv21/Memory-Allocator-In-C/blob/main/src/memAlloc.c).## Compiling and using our memory allocator
We’ll be compiling our memory allocator and then run a utility like **ls** using our memory allocator.
First compile it as a library file.
```bash
$ gcc -o memAlloc.so -fPIC -shared memAlloc.c
```Set the environment variable `LD_PRELOAD` to the path of a shared object, this way our file will be loaded before any other library.
```bash
$ export LD_PRELOAD=$PWD/memAlloc.so
```Now to test,
```bash
$ ls
memAlloc.c memAlloc.so
```And now our memory allocator is serving `ls`!.