3 ms·
Ada’s memory management is a mix of memory pools, RAII, and manual memory management. It often isn’t necessary to explicitly use pointers to dynamically alloca
by csb6 4y ago
Ada’s memory management is a mix of memory pools, RAII, and manual memory management.
It often isn’t necessary to explicitly use pointers to dynamically allocated memory. For example, Ada lets you return an array of unknown size by value from a function. These unconstrained objects are stored on what is called a “secondary stack”, which is basically a special allocation pool for holding these objects managed by the language runtime.
When you do use pointers, the compiler is very strict to try and avoid dangling pointers. You can also create custom pointer types and assign them to memory pools, so dynamic allocations of that pointer type get made in the pool (and not in the normal heap).
You can also use manual memory management (using the `new` keyword and the `Unchecked_Deallocation` function similar to malloc() and free()).
There is also a finalizer class you can inherit from that adds a destructor to record types, so you can use RAII, too.