File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
courses/fundamentals_of_ada/140_access_types Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments