• Stars
    star
    214
  • Rank 184,678 (Top 4 %)
  • Language
    C
  • Created over 8 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple memory allocator - Memory allocation 101

memalloc

memalloc is a simple memory allocator.

It implements malloc(), calloc(), realloc() and free().

Article

Write a simple memory allocator

(http://arjunsreedharan.org/post/148675821737/write-a-simple-memory-allocator)

Compile and Run

gcc -o memalloc.so -fPIC -shared memalloc.c

The -fPIC and -shared options makes sure the compiled output has position-independent code and tells the linker to produce a shared object suitable for dynamic linking.

On Linux, if you set the enivornment variable LD_PRELOAD to the path of a shared object, that file will be loaded before any other library. We could use this trick to load our compiled library file first, so that the later commands run in the shell will use our malloc(), free(), calloc() and realloc().

export LD_PRELOAD=$PWD/memalloc.so

Now, if you run something like ls, it will use our memory allocator.

ls
memalloc.c		memalloc.so		README.md

or

vim memalloc.c

You can also run your own programs with this memory allocator.

Once you're done experimenting, you can do unset LD_PRELOAD to stop using our allocator.

More Repositories

1

mkernel

A minimalist kernel
C
1,308
star
2

mkeykernel

A kernel that can read from keyboard and print on-screen
C
650
star
3

socketfun

collection of well commented socket programming code
C
99
star
4

facebook-friends-ranking-score

Find your Facebook Friends Ranking Score http://arjunsreedharan.org/post/65979958297/find-your-facebook-friends-ranking-score
JavaScript
84
star
5

systemd-example-startup

example file to tell systemd to start a shell script at boot
Shell
51
star
6

turn-off-screen

Turn off your screen display
Python
46
star
7

hide-data-in-ptr

how to hide data inside pointers
C
32
star
8

actions-dashboard

Github Actions dashboard
Shell
30
star
9

get-a-random-proxy-address

returns a random working proxy address
Python
17
star
10

tiny-elf

Tiniest ELF (Executable and Linkable Format) executable
Assembly
11
star
11

linux-0.01

Historic linux kernel from ftp://ftp.kernel.org/pub/linux/kernel/Historic/
C
11
star
12

wikicoding

the code that powers Wikicoding, the wikipedia of code.
Python
11
star
13

pystorage

A simple python file-storage solution using dropbox and google app engine
Python
11
star
14

whats

a tool to quickly lookup something from the command line, written in Go
Go
10
star
15

findrep

A tool to easily find and replace from files
C
10
star
16

golang-101

some trivial examples in golang
Go
8
star
17

strbuf

standalone version of git's strbuf api
C
6
star
18

actions-dashboard-paketo

Shell
4
star
19

imagetweet

tweet longer messages using Images. Code that powers imagetweet.com
PHP
4
star
20

oauthRequest

a simple php wrapper for making OAuth Requests
PHP
4
star
21

arjun024.github.io

user page
JavaScript
1
star
22

ruby-nginx-multi-app

HTML
1
star
23

arjunsreedharan.org

backup code for template of http://arjunsreedharan.org
HTML
1
star
24

nitcbot

the code that powers @nitcbot
PHP
1
star
25

extract-mp3-from-playlist

Extract mp3 files from a Windows Media Player playlist (.wpl) to a folder
Python
1
star
26

heuristic-based-bgp-hjack-analysis

Measuring the propagation of BGP Hijacks
Python
1
star