News for hackers. Stuff that matters.
Re:Why I Write Games in C (yes, C) by einpoklum on Saturday September 21, 2019 @03:17PM (#21037303)
That's not entirely true. If you only rely on RAII you may end up with millions of shared pointers, each of which needs to be managed independently and having its own overhead. They may also be independently allocated, which means they will be fragmented in memory. Not so simple.
Re:Why I Write Games in C (yes, C) by flatline on Saturday September 21, 2019 @04:02PM (#21037582)
I think it’s safe to say for the general case that if you have millions of widely-shared smart pointers you are not following RAII principles. At that point you are left with poorly-implemented reference counting, with a ton of synchronization overhead.
Re:Why I Write Games in C (yes, C) by einpoklum on Saturday September 21, 2019 @05:10PM (#21037946)
Which RAII principle would you say would be broken in this scenario?
Re:Why I Write Games in C (yes, C) by flatline on Saturday September 21, 2019 @05:23PM (#21037995)
If the lifetime of your objects are not bound to any scope, I’d say you’re well out of the realm of any real benefit that RAII would provide over GC. This is a continual problem that arises with a shared ownership model. The specific principle this violates is encapsulation - there is still encapsulation at the level of the smart pointer, but not with its consumers.
Re:Why I Write Games in C (yes, C) by ncmncm on Sunday September 22, 2019 @04:25AM (#21040282)
Indeed, if you have a noticeable number of shared pointers, you are Doing It Wrong. A few here and there at top level are harmless, but if they have leaked into public interfaces or low-level infrastructure, you might better pitch the whole codebase and start over.