Gem #20: Using pragma Shared_Passive for data persistence Author: Pascal Obry, EDF R&D Abstract: Ada Gem #20 Using pragma Shared_Passive for data persistence. Let s get started ¦ Data persistence can be achieved in many ways starting as simple as using hand-written code to store and load data into some text files to something as complex as mapping the data into a relational or object database for example. In some cases we just want to store the content of a set of variables. Ada provides such support using the Annex-E shared passive pragma. Let s write a simple counter that will increment each time the application is run: package Store is pragma Shared_Passive; Counter : Natural := 0; end Store; And yes that s all! The variable s current value is read at elaboration time and written during program finalization. Shared passive unit state is saved on disk using one file for each top-level declaration (variables, protected objects). The filename is composed of the unit name and the declaration name separated by a dot. The above counter variable state will be saved into the file named store.counter for example. So the main is as simple as:
/lp/association-for-computing-machinery/gem-20-using-pragma-shared-passive-for-data-persistence-yS7Do4EBLR