12 ms·
> Safe languages usually want to abort if they encounter an out-of-memory (OOM) situation. SQLite is designed to recover gracefully from an OOM. As someone who
by Drew_ 9mo ago
> Safe languages usually want to abort if they encounter an out-of-memory (OOM) situation. SQLite is designed to recover gracefully from an OOM.
As someone who runs into this problem a lot, this is pretty cool! Does anyone know how they can recover from this in SQLite?
- JackSlateur 9mo agoAn oom is when malloc failed So you have to ensure that in such situation, you can execute code that does not require more memory: ensure that the rest only free stuff, or preallocate structures for that purpose
- lelanthran 9mo ago> As someone who runs into this problem [OOM]a lot, this is pretty cool! Does anyone know how they can recover from this in SQLite? How are you running into it? If you're writing in C, idiomatic code works (check the return values of functions that allocate!) If you're in C++, Rust or similar, you have to write pretty non-idiomatically to recover from an allocation failure.
- zabzonk 9mo agohow exactly do you think C and C++ differ here?
- lelanthran 9mo ago> how exactly do you think C and C++ differ here? `new` throws, `malloc` returns. That's a pretty big difference! Idiomatic C++ code never puts a `try` around `new`, while idiomatic C code always checks the return from an allocation.
- zabzonk 9mo agoWell: https://en.cppreference.com/w/cpp/memory/new/nothrow.html https://en.cppreference.com/w/cpp/memory/new/nothrow.html I thought you were talking about the use of malloc in both languages - you never mentioned new in your first post. and i think we have different views on what is "idiomatic" in the languages.
- lelanthran 9mo ago> I thought you were talking about the use of malloc in both languages - you never mentioned new in your first post. and i think we have different views on what is "idiomatic" in the languages. That's fair, but malloc is certainly non-idiomatic, isn't it?