Skip to content

Harshitv21/Memory-Allocator-In-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Memory Allocator in C

Vs Code Badge WSL Badge

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 for anyone who wants to implement or try it for yourself.
Source code for this project can be found here.

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.

$ 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.

$ export LD_PRELOAD=$PWD/memAlloc.so

Now to test,

$ ls
memAlloc.c		memAlloc.so

And now our memory allocator is serving ls!.

About

A basic implementation of memory allocation using C.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages