Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Malloc can indeed be implemented in a handful of bytes, but that's nog going to perform well.

Doing malloc well is actually quite a bit of work. You need to group allocations by size, manage alignment, request and release pages from the OS/browser implement reallocate, etc. A typical malloc implementation is actually a combination of several different allocation strategies.



The best solution is to reduce the amount of alloc/free calls in your code, then you can just as well use a slow-and-small allocator like emmalloc since allocator overhead doesn't matter anymore: https://github.com/emscripten-core/emscripten/blob/main/syst...

(e.g. if memory management overhead shows up in the profiler, the proper solution is not to go looking for a faster general-purpose allocator, but to reduce the amount of calls into the allocator)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: