3 ms·
Batching/arenas can get you very far. If you adopt the zig/c object model as “things that have data” most destructors become useless. Resource management also c
by cwood-sdf 7mo ago
Batching/arenas can get you very far. If you adopt the zig/c object model as “things that have data” most destructors become useless. Resource management also can be accomplished at the batch level (eg you can free a bunch of fd’s all at once with a management layer rather than having each File object implicitly manage its own fd). For memory management, i believe proper use of arenas and batching tends to be faster than each object managing its own memory but idrk tbh. What the author is saying is that you dont have to have raii, you can use approaches like the one i described and they can still be pretty safe if you know what youre doing, but rust’s model basically prevents this if youre using rust idiomatically
- markisus 7mo agoYeah if your program has a natural notion of a "frame" (eg most video games), you can do memory management by simply incrementing an integer (bump allocation). At the end of your frame, you reset the integer to zero. You can't really get any faster than that. An additional benefit of this style of allocation over malloc/free is that you can get a lot of the same type of objects contiguous in memory so that iteration over them is a lot faster because there are fewer cache misses.
- goku12 7mo agoI forgot about the arena approach. So, which language is the best to try it out? How does Zig look? I have been putting off my attempts to learn it, due to the fact that it's not stable yet. Perhaps it's time to give it another go?