3 ms·
> Can someone speak, at a high-level, on how Ada manages memory? It is low level ;). There is a function like malloc that allocates memory, but there is no fr
by throwaway81523 4y ago
> Can someone speak, at a high-level, on how Ada manages memory?
It is low level ;). There is a function like malloc that allocates memory, but there is no free, since re-using freed memory is a common source of bugs in C programs. The idea is that you do all your memory allocation (buffers etc.) during program startup. If an allocation fails, you log the error and exit. Once the program is up and running, you don't allocate any more. Embedded systems, remember. You do everything in fixed memory regions. In critical systems there are some tools that make sure your stack allocations never exceed whatever. Ada programs are not allowed to crash.
That said, most Ada implementations do have something like free, but it is not part of the standard and you are supposed to be very careful with it.
You might like this, "random walk through Ada": http://cowlark.com/2014-04-27-ada/index.html http://cowlark.com/2014-04-27-ada/index.html
- 3a2d29 4y agoAlso I think Ada is more memory safe than both C++ and rust! (with SPARK!)
- sai_c 4y agoNot to be nitpicking, but there is a free(), and it is called "Unchecked deallocation". See https://www.adaic.org/resources/add_content/standards/05aarm/html/AA-13-11-2.html https://www.adaic.org/resources/add_content/standards/05aarm....
- pjmlp 4y agoPeople keep repeating Ada 83 features, as if nothing has changed. Ada has free() via "Unchecked_Dealocation", which since Ada 95 is hardly directly called, beacause the language introduced support for RAII via controlled types. Many data types like strings and vectors are capable of dynamic managing memory themselves, thus no need for the malloc()/free() dance like in C. When stack allocations, or other kinds of allocations fail from those dynamic types, an exception is thrown, that can be caught and the same operation retried with smaller sizes. With SPARK integration into standard Ada, formal proofs can be used to handle how memory and other resources are being managed. Finally, due to Rust's sucess bringing affine types into the mainstream, Ada is also having a go into affine types, influenced by ParaSail experiment whose author now works at AdaCore (not to forget the remaining 6 Ada vendors still in business).