Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/NanXiao/umalloc

A tiny Unix dynamic memory allocator library.
https://github.com/NanXiao/umalloc

Last synced: 11 days ago
JSON representation

A tiny Unix dynamic memory allocator library.

Lists

README

        

# umalloc
A tiny Unix dynamic memory allocator library. The allocated memory is divided into `4` parts:

-------------------------------------------------
| | | | |
|chunk_size|head_guard| chunk |tail_guard|
| | | | |
-------------------------------------------------
Besides the allocated memory are initialized to `0`, when free the memory, it will check following cases:

(1) Both up and down out-of-bound memory error;
(2) Double-free pointer error.

## Usage
$ git clone https://github.com/NanXiao/umalloc.git
$ cd umalloc
$ make && make install

## Example:

#include
#include
#include
#include
#include

int main(void)
{
uint32_t size = 1;
for (size = 1; size < UINT32_MAX; size++)
{
printf("size=%" PRIu32 "\n", size);
char *p = umalloc(size);
memset(p, 0xFF, size);
p = urealloc(p, size - 1);
p = urealloc(p, size);
ufree(p);
}
return 0;
}

Build and run it:

$ cc -I/usr/local/include -L/usr/local/lib -Wall -o test test.c -lumalloc
$ ./test