Don’t store your structure lengths at pointer-4. Thank you.
Conversation
This Tweet was deleted by the Tweet author. Learn more
I got no work done for the rest of the day after I discovered that macro. I was just browsing kernel code and looking at a vmcore in crash as though I had stumbled upon evidence of a murder.
1
Are there any malloc implementations that are NOT cursed?
1
Well, I made github.com/GrapheneOS/har, so it's hard for me to consider it cursed. It's not a performance-oriented allocator though. If it was it would have small thread caches, free lists in slabs instead of bitmaps and wouldn't have all the sanity checks and security features.
1
1
To be fair to jemalloc, they have the super cursed red-black tree implementation for real reasons. It's blazing fast and with RB_COMPACT the nodes are only 2 words, with the color bit packed into a pointer. It's intrusive so no extra allocation and multiple can go in an object.
It goes out of the way to avoid recursion in any of the hot paths to avoid the cost of creating stack frames which makes it a lot messier. I definitely do think jemalloc is very over-engineered and that a simpler approach from scratch can be better all around but it's not easy.


