Last active
April 6, 2022 12:37
-
-
Save jeremy-rifkin/c45940d36cd6cc414f7c71499412eca1 to your computer and use it in GitHub Desktop.
High performance 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
uintptr_t base; | |
const uintptr_t height = 100000000; | |
std::mt19937 rng; | |
[[gnu::constructor]] void init_malloc() { | |
base = (uintptr_t) sbrk(height); | |
} | |
void* malloc(size_t) { // parameter ignored, we don't need it | |
return (void*)(base + rng() % height); // odds of any collision is like, low | |
} | |
void free(void*) {} // no-op |
64
commented
Apr 1, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment