The kernel radar: folios, multi-generational LRU, and Rust
The kernel radar: folios, multi-generational LRU, and Rust
Posted Feb 6, 2022 3:02 UTC (Sun) by HelloWorld (guest, #56129)In reply to: The kernel radar: folios, multi-generational LRU, and Rust by NYKevin
Parent article: The kernel radar: folios, multi-generational LRU, and Rust
Well, most destructors don't require allocation but do free up some memory. This means that when a bad_alloc is thrown, there's a pretty good chance that by the time you reach a destructor that allocates, some memory has already been freed by a destructor that ran before, and so your allocation may very well succeed. There are cases where it's better to try to recover from an allocation failure and sometimes fail than to not try at all.
Also, you might be able to allocate whatever memory you need to run the destructor in the constructor, thus avoiding the need to allocate in the destructor.