Skip to content

Instantly share code, notes, and snippets.

@jeremy-rifkin
Last active April 6, 2022 12:37
Show Gist options
  • Save jeremy-rifkin/c45940d36cd6cc414f7c71499412eca1 to your computer and use it in GitHub Desktop.
Save jeremy-rifkin/c45940d36cd6cc414f7c71499412eca1 to your computer and use it in GitHub Desktop.
High performance malloc implementation
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
Copy link

64 commented Apr 1, 2021

galaxybrain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment