**persistence**,
a C++ code which
demonstrates how to initialize, get, or set data stored
within a function, using static/persistent/saved/local memory.

This type of data storage is sometimes referred to as "static memory" or "persistent memory" or "saved memory".

Several examples are offered here, each embodied in a function.

- constants() stores the value of three physical constants, and returns them. It is not very ambitious.
- counter() "remembers" how many times it has been called, and prints this value.
- abc() stores the value of three real numbers, which are initialized to 1, 2, and 3. The user can request the current values, or request that they be printed, or can set them to new values.
- stats() accepts, one at a time, a sequence of real numbers. It internally updates the sum, min, mean, max, variance and standard deviation of the entire sequence, and can report the current values of these quantities at any time.
- byname() internally stores three variables. The user can access any one of these variables, by naming the kind of access, naming the variable to be accessed, and the new value if any, to be assigned to it.

The computer code and data files made available on this web page are distributed under the MIT license

**persistence** is available in
a C version and
a C++ version and
a FORTRAN90 version and
a MATLAB version and
an Octave version and
a Python version and
an R version.

- persistence.sh, compiles all the source codes.

- abc.cpp, stores, saves, and returns variables "a", "b", "c", using the form "abc(&ain,&bin,&cin,&aout,&bout,&cout)";
- abc.sh, compiles the source code.
- abc.hpp, the include file.

- byname.cpp, sets, gets, prints or resets any of three variables "alpha", "beta", "gamma", which are referenced by name, using actions "print", "get", "set", or "reset", using the form "value_out=byname(action,name,&value_in)";
- byname.sh, compiles the source code.
- byname.hpp, the include file.

- constants.cpp, saves and returns constants "g", "c", "n", using the form "constants(&g,&c,&h)";
- constants.sh, compiles the source code.
- constants.hpp, the include file.

- counter.cpp, prints the number of times it has been called, using the form "counter()";
- counter.sh, compiles the source code.
- counter.hpp, the include file.

- stats.cpp, initializes, updates, and outputs running values of statistical quantities of a sequence of data supplied one value at a time, using the form "stats(&x,&n,&x_sum,&x_min,&x_mean,&x_max,&x_var,&x_std)".
- stats.sh, compiles the source code.
- stats.hpp, the include file.