3 ms·
There was an interesting paper I read the other day about a scheme for guaranteed constant time dynamic allocation and deallocation. The idea was you make all o
by slaymaker1907 2y ago
There was an interesting paper I read the other day about a scheme for guaranteed constant time dynamic allocation and deallocation. The idea was you make all objects identical in size (they used 32 bytes). Then, on deallocation of a 32 byte node, you just put the node on a free list. Then, when a new allocation request comes in decrement the ref count of any *direct* reference(s) and move those objects to the free list if their ref count goes to 0. Therefore, even if you have some huge list that goes out of scope, only the 1st node goes on the freelist, but the rest of the list will get freed eventually assuming you continue to allocate new objects.
I thought it was a really cool idea and it seems totally viable for things like a game engine. All the pointer chasing would be expensive, but being able to freely allocate memory without much lag would be a really nice property, particularly for games with plugins like Roblox, Factorio, etc. where code quality is often out of your control.
https://lptk.github.io/files/ctrc-2024-05-09.pdf https://lptk.github.io/files/ctrc-2024-05-09.pdf
- bjconlan 2y agoI think this practice is generally good for "most fast things" I noticed that https://github.com/kparc/ksimple/blob/31370a2c799a2a0e491d52be6fded818b50d3908/a.h#L10 https://github.com/kparc/ksimple/blob/31370a2c799a2a0e491d52... uses this approach too (this is the core of the k apl which is used in finance and engineering industries so very fast for data processing applications. Not sure how it fares in a more general setting but wouldn't be surprised if it was also competitive.
- spintin 2y ago[dead]