\section{Read-only Data}
\label{readonly}

Since \charmpp\ does not allow global variables,
it provides a special mechanism for sharing
data amongst all objects. {\it Read-only} variables of simple data types or
compound data types including messages and arrays are used to share information
that is obtained only after the program begins execution and does not change
after they are initialized in the dynamic scope of the {\tt main} function of
the \kw{mainchare}. They are broadcast to every PE by the \charmpp\ runtime,
and can be accessed in the same way as \CC ``global'' variables on any PE.
Compound data structures containing pointers can be made available as read-only
variables using read-only messages(see section~\ref{messages}) or read-only arrays(see section~\ref{basic arrays}.  Note that memory
has to be allocated for read-only messages by using \kw{new} to create the
message in the {\tt main} function of the \kw{mainchare}. 

Read-only variables are declared by using the type modifier \kw{readonly},
which is similar to \kw{const} in \CC. Read-only data is specified in the {\tt
.ci} file (the interface file) as: 

\begin{alltt}
 readonly Type ReadonlyVarName;
\end{alltt}

The variable \uw{ReadonlyVarName} is declared to be a read-only variable of
type \uw{Type}. \uw{Type} must be a single token and not a type expression.

\begin{alltt}
 readonly message MessageType *ReadonlyMsgName;
\end{alltt}

The variable \uw{ReadonlyMsgName} is declared to be a read-only message of type
\uw{MessageType}. Pointers are not allowed to be readonly variables unless they
are pointers to message types. In this case, the message will be initialized on
every PE.

\begin{alltt}
 readonly Type ReadonlyArrayName [arraysize];
\end{alltt}

The variable \uw{ReadonlyArrayName} is declared to be a read-only array of type
\uw{Type} with \uw{arraysize} elements. \uw{Type} must be a single token and
not a type expression. The value of \uw{arraysize} must be known at compile
time.

Read-only variables must be declared either as global or as public class static
data in the C/\CC\ implementation files, and these declarations have the usual
form:

\begin{alltt}
 Type ReadonlyVarName;
 MessageType *ReadonlyMsgName;
 Type ReadonlyArrayName [arraysize];
\end{alltt}

Similar declarations preceded by \kw{extern} would appear in the {\tt
.h} file. 

{\it Note:}  The current \charmpp\ translator cannot prevent
assignments to read-only variables.  The user must make sure that no
assignments occur in the program outside of the mainchare constructor.

For concrete examples for using read-only variables, please refer to Travelling
Salesman Problem (TSP) in
\examplerefdir{hello}, and GaussSeidel
elimination in \examplerefdir{gaussSeidel3D}.
