News for hackers. Stuff that matters.
Re:Wuffs’ PNG image decoder by andrepd on Tuesday April 06, 2021 @05:46PM (#26717770)
Isn't that stupidly limiting?
Re:Wuffs’ PNG image decoder by dahart on Wednesday April 07, 2021 @12:25AM (#26720587)
Some people consider avoiding heap allocations to be smartly limiting. ;) It’s not really that limiting either, when you learn the techniques for it.

There’s a famous list of NASA’s rules for safety-critical code that you’ll see pop up now and then, that subscribes to the “avoid heap memory allocation” philosophy. https://en.wikipedia.org/wiki/The_Power_of_10:_Rules_for_Dev...

It’s not nearly as true anymore today, but working in console games 10-20 years ago, it was very common to try to avoid dynamic memory allocation because it was viewed as slow, unsafe, and unnecessary. A common strategy was to statically pre-allocate a single block of the worst-case memory needed for a given feature, because you need to be prepared to hit the worst case without crashing, so you might as well just reserve the max and focus on reducing what the maximum possible usage is.

I once debugged a crash in a console game that was caused by someone trying to be too clever by half with their allocation and copy constructors. We had a team of a dozen people working on the crash through a weekend during crunch because the crash only occurred in a release build on the console dev kit. The cost of this one stupid bug due to using memory allocation could literally accounted for in the thousands of dollars. I basically had to write a mini one-off release-build stack-tracing sampling debugger in order to trap it. So, anyway, long story short, I’m old enough to appreciate why some people suggest that avoiding allocations is a good thing.

Re:Wuffs’ PNG image decoder by danielheath on Tuesday April 06, 2021 @07:21PM (#26718581)
Depends. AFAICT it’s designed to be embedded in a c project; in that context, it’s merely saying “the wuffs part does not allocate; do that in the c code”.
Re:Wuffs’ PNG image decoder by andrepd on Tuesday April 06, 2021 @08:12PM (#26718976)
Makes sense.
Re:Wuffs’ PNG image decoder by zamalek on Wednesday April 07, 2021 @01:30AM (#26720896)
Seems like an honest question. "Stupidly" is a key word there because humans are, without exception, vastly too stupid to deal with the combinatorial explosion that the heap presents. This is a key goal of languages like Rust: allow the compiler to deal with the complexity for you.

There are vastly fewer interacting elements when you restrict yourself to the stack: basically logic errors and pointer arithmetic become the key concerns (and Wuffs supposedly deals with the latter). Really smart people may be able to completely reason about this space.

Developers are known for imposter syndrome, but we have an unhealthy amount of overconfidence at the same time.

Re:Wuffs’ PNG image decoder by phire on Wednesday April 07, 2021 @04:23AM (#26721821)
Yes.

I'm not so sure about the usefulness for an image decoder.

But if you are designing safety critical realtime software for controlling a car, then you kind of want the extra reliability guarantees that avoiding the heap gives you.

Re:Wuffs’ PNG image decoder by amelius on Tuesday April 06, 2021 @06:45PM (#26718321)
After NoSQL, now we also have NoAlloc :)