-
+ 88AF8572F4610D88A155E834189F6FA61F21CFD3198AA73C3F68042D4B60299061C58B3770CDF7086F6C834FB7B39F8C604171FC156CA041F6FCDFE24607C970
cryostat/demo/cryodemo.adb
(0 . 0)(1 . 76)
112 ------------------------------------------------------------------------------
113 ------------------------------------------------------------------------------
114 -- This file is part of 'CryoDemo', a tutorial example for 'Cryostat'. --
115 -- --
116 -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) --
117 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
118 -- --
119 -- You do not have, nor can you ever acquire the right to use, copy or --
120 -- distribute this software ; Should you use this software for any purpose, --
121 -- or copy and distribute it to anyone or in any manner, you are breaking --
122 -- the laws of whatever soi-disant jurisdiction, and you promise to --
123 -- continue doing so for the indefinite future. In any case, please --
124 -- always : read and understand any software ; verify any PGP signatures --
125 -- that you use - for any purpose. --
126 ------------------------------------------------------------------------------
127 ------------------------------------------------------------------------------
128
129 with Interfaces; use Interfaces;
130 with ada.text_io; use ada.text_io;
131
132 with Cryostat;
133
134
135 procedure CryoDemo is
136
137 -- Path on disk for the example Cryostat backing file :
138 File_Path : constant String := "cryotest.bin";
139
140 -- Now, let's define an example data structure to place in a Cryostat :
141
142 -- Example payload array's element type: byte.
143 subtype ADatum is Unsigned_8;
144
145 -- Let's make it 512MB - far bigger than a typical stack, to demonstrate
146 -- that it will in fact reside in the Cryostat, rather than on the stack :
147 A_MBytes : constant Unsigned_32 := 512;
148
149 -- Example payload: an array.
150 subtype ARange is Unsigned_32 range 0 .. (A_MBytes * 1024 * 1024) - 1;
151
152 -- Complete the definition of the payload data structure :
153 type TestArray is array(ARange) of ADatum;
154
155 -- Declare a Cryostat which stores a TestArray :
156 package Cryo is new Cryostat(Form => TestArray,
157 Path => File_Path,
158 Writable => True, -- Permit writing
159 Create => True); -- Create file if not exists
160
161 -- Handy reference to the payload; no pointerisms needed !
162 T : TestArray renames Cryo.Item;
163
164 -- T can now be treated as if it lived on the stack :
165
166 begin
167
168 Put_Line("T(0) before : " & ADatum'Image(T(0)));
169 Put_Line("T(Last) before : " & ADatum'Image(T(T'Last)));
170
171 -- Increment each of the elements of T :
172 for i in T'Range loop
173 T(i) := T(i) + 1;
174 end loop;
175
176 Put_Line("T(0) after : " & ADatum'Image(T(0)));
177 Put_Line("T(Last) after : " & ADatum'Image(T(T'Last)));
178
179 --- Optional, finalizer always syncs in this example
180 -- Cryo.Sync;
181
182 --- Test of Zap -- uncomment and get zeroized payload every time :
183 -- Cryo.Zap;
184
185 Put_Line("OK.");
186
187 end CryoDemo;