persistence
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.
Licensing:
The computer code and data files made available on this web page
are distributed under
the MIT license
Languages:
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.
Related Data and Programs:
persistence_test
Source Code:
-
abc.c,
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.h,
the include file.
-
byname.c,
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.h,
the include file.
-
counter.c,
prints the number of times it has been called,
using the form "counter()";
-
counter.sh,
compiles the source code.
-
counter.h,
the include file.
-
stats.c,
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.h,
the include file.
Last modified on 07 May 2021.