Hacker News new | ask | show | jobs
by ozgrakkurt 9 days ago
You might have a limited budget per incoming request in a http server for example. Then you want all of the code that http handler calls to be able to handle an error of type something like OutOfMemory.

This is a very good ability to have in an application like a database.

1 comments

Such things should be solved in more nice way, not by manually checking every allocation. Like via lightweight threads, with each of them having their own memory and a scheduler, which kills threads exceeding their memory limit.
This compilicates things more compared to functions returning Result<>.

You also get locality benefits from bump style allocators. And you don't need SmallVec or similar optimization containers. And you also avoid mental overhead of managing many allocations in your head (or using a language with borrow checking).

> This compilicates things more compared to functions returning Result<>.

Checking each Result in a large program is more complicated than having a runtime library handling memory limits properly.

> And you also avoid mental overhead of managing many allocations in your head

That's exactly what languages like Zig force you to do, compared to something like C++ or Rust.

> or using a language with borrow checking

borrow checking gives memory safety. It's also important to have.