1 ------------------------------------------------------------------------------
2 ------------------------------------------------------------------------------
3 -- This file is part of 'CryoDemo', a tutorial example for 'Cryostat'. --
4 -- --
5 -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) --
6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
7 -- --
8 -- You do not have, nor can you ever acquire the right to use, copy or --
9 -- distribute this software ; Should you use this software for any purpose, --
10 -- or copy and distribute it to anyone or in any manner, you are breaking --
11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
12 -- continue doing so for the indefinite future. In any case, please --
13 -- always : read and understand any software ; verify any PGP signatures --
14 -- that you use - for any purpose. --
15 ------------------------------------------------------------------------------
16 ------------------------------------------------------------------------------
17
18 with Interfaces; use Interfaces;
19 with ada.text_io; use ada.text_io;
20
21 with Cryostat;
22
23
24 procedure CryoDemo is
25
26 -- Path on disk for the example Cryostat backing file :
27 File_Path : constant String := "cryotest.bin";
28
29 -- Now, let's define an example data structure to place in a Cryostat :
30
31 -- Example payload array's element type: byte.
32 subtype ADatum is Unsigned_8;
33
34 -- Let's make it 512MB - far bigger than a typical stack, to demonstrate
35 -- that it will in fact reside in the Cryostat, rather than on the stack :
36 A_MBytes : constant Unsigned_32 := 512;
37
38 -- Example payload: an array.
39 subtype ARange is Unsigned_32 range 0 .. (A_MBytes * 1024 * 1024) - 1;
40
41 -- Complete the definition of the payload data structure :
42 type TestArray is array(ARange) of ADatum;
43
44 -- Declare a Cryostat which stores a TestArray :
45 package Cryo is new Cryostat(Form => TestArray,
46 Path => File_Path,
47 Writable => True, -- Permit writing
48 Create => True); -- Create file if not exists
49
50 -- Handy reference to the payload; no pointerisms needed !
51 T : TestArray renames Cryo.Item;
52
53 -- T can now be treated as if it lived on the stack :
54
55 begin
56
57 Put_Line("T(0) before : " & ADatum'Image(T(0)));
58 Put_Line("T(Last) before : " & ADatum'Image(T(T'Last)));
59
60 -- Increment each of the elements of T :
61 for i in T'Range loop
62 T(i) := T(i) + 1;
63 end loop;
64
65 Put_Line("T(0) after : " & ADatum'Image(T(0)));
66 Put_Line("T(Last) after : " & ADatum'Image(T(T'Last)));
67
68 --- Optional, finalizer always syncs in this example
69 -- Cryo.Sync;
70
71 --- Test of Zap -- uncomment and get zeroized payload every time :
72 -- Cryo.Zap;
73
74 Put_Line("OK.");
75
76 end CryoDemo;