Comment by Philpax

8 hours ago

The article mentions anyhow:

> That is the reason why mature error handling libraries hide the error behind a thin pointer, approached pioneered in Rust by failure and deployed across the ecosystem in anyhow. But this requires global allocator, which is also not entirely zero cost.

Oh oops … IDK how I missed that … but also that seems to really undercut the article's own thesis then if they're aware of it.

> But this requires global allocator, which is also not entirely zero cost.

Heap allocs are not free. But then, IDK that the approach of using the unwinding infra is any better. You still have to store the associated data somewhere, & then unwind the stack. That "somewhere" might require a global allocator¹.

(¹Say you put the associated data on the stack, and unwind, and your "recovery point"/catch/etc. site might get a pointer to it. Put what if that recovery point then calls a function, and that function requires more stack depth that exists prior to the object?

I supposed you could put it somewhere, and then move it up the stack into the stack frame of the recovery function, but that's more expensive. That might work, though.

But since C++ impls put it on the heap, that leads me to assume there's a gotcha somewhere here.)