For safe resource finalization, Ada provides `Ada.Finalization.Controlled`. This enables you to implement RAII, smart pointers, and other ways of safe finalization. `Ada.Unchecked_Deallocation` is just the bare-metal tool you can implement more intelligent finalization with (because in the end, someone needs to deallocate the memory).
Re:A Random Walk Through Ada (2014)
by catnaroek on Wednesday November 02, 2016 @07:25AM
(#12853662)
Without substructural types, no matter how much lipstick you put on the pig, use after free will always be possible.
Just like Rust with unsafe blocks.
There are ways in Ada to write programs without ever having to call Unchecked_Deallocation.
Good luck having the compiler eliminate bounds checking for library code.
> There’s a generic function in the standard library called `Ada.Unchecked_Deallocation`, which frees memory to the heap.
A systems language without a safe resource finalization story is simply an unsafe language. This isn’t some fringe use case. Finalizing resources is a common operation in systems programming.
Other “benefits” of Ada just consist in bloating the core language with stuff that can be reasonably done in libraries: bounds checking (in ML, this is just a functor that produces an abstract type of bounds-checked integers), concurrency abstractions (as Rust has shown), etc.