------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- This file is part of 'CryoDemo', a tutorial example for 'Cryostat'. -- -- -- -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) -- -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -- -- -- -- You do not have, nor can you ever acquire the right to use, copy or -- -- distribute this software ; Should you use this software for any purpose, -- -- or copy and distribute it to anyone or in any manner, you are breaking -- -- the laws of whatever soi-disant jurisdiction, and you promise to -- -- continue doing so for the indefinite future. In any case, please -- -- always : read and understand any software ; verify any PGP signatures -- -- that you use - for any purpose. -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Interfaces; use Interfaces; with ada.text_io; use ada.text_io; with Cryostat; procedure CryoDemo is -- Path on disk for the example Cryostat backing file : File_Path : constant String := "cryotest.bin"; -- Now, let's define an example data structure to place in a Cryostat : -- Example payload array's element type: byte. subtype ADatum is Unsigned_8; -- Let's make it 512MB - far bigger than a typical stack, to demonstrate -- that it will in fact reside in the Cryostat, rather than on the stack : A_MBytes : constant Unsigned_32 := 512; -- Example payload: an array. subtype ARange is Unsigned_32 range 0 .. (A_MBytes * 1024 * 1024) - 1; -- Complete the definition of the payload data structure : type TestArray is array(ARange) of ADatum; -- Declare a Cryostat which stores a TestArray : package Cryo is new Cryostat(Form => TestArray, Path => File_Path, Writable => True, -- Permit writing Create => True); -- Create file if not exists -- Handy reference to the payload; no pointerisms needed ! T : TestArray renames Cryo.Item; -- T can now be treated as if it lived on the stack : begin Put_Line("T(0) before : " & ADatum'Image(T(0))); Put_Line("T(Last) before : " & ADatum'Image(T(T'Last))); -- Increment each of the elements of T : for i in T'Range loop T(i) := T(i) + 1; end loop; Put_Line("T(0) after : " & ADatum'Image(T(0))); Put_Line("T(Last) after : " & ADatum'Image(T(T'Last))); --- Optional, finalizer always syncs in this example -- Cryo.Sync; --- Test of Zap -- uncomment and get zeroized payload every time : -- Cryo.Zap; Put_Line("OK."); end CryoDemo;