Skip to content

Instantly share code, notes, and snippets.

View hypervis0r's full-sized avatar
💣
0wned

Hypervisor hypervis0r

💣
0wned
View GitHub Profile
@jeremy-rifkin
jeremy-rifkin / malloc.hpp
Last active April 6, 2022 12:37
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