In Ada 95, request FUNCTION to delete an array other than its name

In Ada 95, request FUNCTION to delete an array other than in the name of the array as arr_name.

In TB, it is MAT REDIM arr_name( 0, 0, …, 0) for as many dimensions as the DIM arr_name( a_int, b_int,…, n_int) originally set up.

You have a few options:

  1. Dynamic arrays in Ada are usually handled through Vectors. See Ada.Containers.Vectors and Ada.Containers.Indefinite_Vectors. The main problem with vectors is lack of slicing operations, so you have to make your own slicing function, but that isn’t too difficult.

  2. If you don’t want to make your own slicing functions you can use an indefinite holder type to handle the memory allocation and deallocation. You can access the array via the Element and Replace_Element operations. See Ada.Containers.Indefinite_Holders.

  3. If you just want to roll your own or are dealing with limited types, you can use access to array types along with the “new” operator and Unchecked_Deallocation. I don’t recommend this way though.

If you create the array at library level, you can’t delete it.
If you create the array in an inner scope, e.g. on a subprogram’s stack, it’ll get deleted when you leave the scope.
If you create the array on the heap (using new) you can delete it whenever you like.

1 Like

Thanks, but all Ada 2022 not 95.

It’s not Ada22 stuff, but you are correct that it isn’t 95 either. I forgot they added containers in Ada2005. Prior to that a lot of folks used the booch components. You can find those here:

https://sourceforge.net/p/booch95/code/ci/default/tree/

You might find some useful things there for later.