3 ms·
You jest, but you'd actually get surprisingly far just doing: void* malloc(size_t size) { static void* everything = 0; void* result = everythin
by munificent 13y ago
You jest, but you'd actually get surprisingly far just doing:
void* malloc(size_t size) {
static void* everything = 0;
void* result = everything;
everything += size;
return result;
}
When people are hacking together VMs for garbage collected languages, the first allocator often looks like this until they get around to actually collecting the garbage.
- apgwoz 13y agoYou can get `free` pretty simply too: https://news.ycombinator.com/item?id=6849471 https://news.ycombinator.com/item?id=6849471
- stephen_g 13y agoDepending on how your memory is mapped, everything should probably be an address higher than the kernel (you can get your linker script to generate the right address). Sometimes the kernel is at the top of the address space though so you could start your heap at the bottom.