Skip to content

Instantly share code, notes, and snippets.

@phamtm
Last active January 2, 2017 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phamtm/977b37f76549bc4a564b4d102bad23e1 to your computer and use it in GitHub Desktop.
Save phamtm/977b37f76549bc4a564b4d102bad23e1 to your computer and use it in GitHub Desktop.
malloc implementation
#include <sys/type.h>
#include <unistd.h>
void* malloc(size_t size) {
void *p;
p = sbrk(0); // Initially, `break` is positioned at start of heap
if (sbrk(size) == (void*) -1)
return NULL;
return p;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment