Last active
January 2, 2017 09:19
-
-
Save phamtm/977b37f76549bc4a564b4d102bad23e1 to your computer and use it in GitHub Desktop.
malloc implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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