top | item 47192871

(no title)

goku12 | 1 day ago

I'm curious about the exact exchange that prompted the author to say this.

> refuse to admit there are alternatives to RAII

I'm even more curious about this. Can the author or anybody else explain what this means specifically? Can anybody list those alternatives other than GC and RC?

PS: Computer Science isn't exactly my primary professional competence.

discuss

order

cwood-sdf|1 day 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|1 day ago

Yeah 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|20 hours ago

I 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?