Skip to content

telepath9000/map_malloc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

map_malloc

A malloc implementation that strictly uses mapped virtual memory spaces.

Structure

Memory spaces are pre-cached in chunks based on size to avoid numerous requests to the kernel. Chunks are stored in three seperate lists, also based on size. Small and medium sized chunks are partitioned into a finite number of small and medium sized allocations as defined by the header. The macros SMALL_BYTES and MED_BYTES can be changed to affect this behavior. If there is no available memory in a chunk, a new chunk is appended to the list. If an allocation is freed for use and it is the last to be freed for use, the chunk is removed from the list and unmapped from memory.

Usage

void *map_malloc(size_t size);

Returns a pointer to a newly reserved memory space of size size in bytes. Returns a NULL pointer on failure.

void map_free(void *ptr);

Frees the reserved address pointed to by ptr. Accepts NULL value pointers.

void *map_realloc(void *ptr, size_t size);

Takes the pointer ptr and returns address of new memory space of size size. The contents of ptr are copied up to size in the new memory space. Returns NULL on failure.

void show_alloc_mem(void);

Displays all memory that is currently being managed by map_malloc.

Install

Run make in the repo directroy to build shared library file.

Alternatively, to install system-wide run sudo make install in the repo directory.

Once installed, in order to compile with the library use -lmap_malloc$(uname -m)_$(uname -s) as a compile flag and include library with #include <map_malloc.h> in the target source files.