Skip to content

Commit fb1e413

Browse files
committed
access: various idioms
1 parent dbb48f1 commit fb1e413

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
=================
2+
Protecting Access
3+
=================
4+
5+
------------------------------
6+
Elaboration Dynamic Allocation
7+
------------------------------
8+
9+
1. Deallocations can cause leaks, corruption
10+
11+
- |rightarrow| Disallow them entirely
12+
13+
2. A dynamically allocated object needs to be deallocated
14+
15+
- |rightarrow| Unless it is global
16+
17+
* |rightarrow| Allow only allocation onto globals
18+
19+
- And restrict them to program elaboration
20+
21+
--------------------------------
22+
Constant Access at Library Level
23+
--------------------------------
24+
25+
.. code:: Ada
26+
27+
type Acc is access T;
28+
procedure Free is new Ada.Unchecked_Deallocation (T, Acc);
29+
30+
A : constant Acc := new T;
31+
32+
* :ada:`A` is :ada:`constant`
33+
34+
* Cannot be deallocated
35+
36+
-------------------------------
37+
Constant Access as Discriminant
38+
-------------------------------
39+
40+
.. code:: Ada
41+
42+
type R (A : access T) is limited record
43+
44+
* :ada:`A` is :ada:`constant`
45+
46+
* Cannot be deallocated
47+
48+
* :ada:`R` is :ada:`limited`, cannot be copied
49+

0 commit comments

Comments
 (0)