Java Reference
In-Depth Information
listofexpressions,which(asthe matrix exampleshows)maythemselvesbearrayini-
tializers. The matrix example results in a table that looks like the following:
1.0F 2.0F 3.0F
4.0F 5.0F 6.0F
ORGANIZING VARIABLES IN MEMORY
Perhaps you're curious about how variables are organized in memory. Figure 1-6
presentsonepossiblehigh-levelorganizationforthe counter , ages ,and matrix
variables, along with the arrays assigned to ages and matrix .
Figure 1-6. The counter variable stores a four-byte integer value, whereas ages and mat-
rix store four-byte references to their respective arrays.
Figure1-6 revealsthateachof counter , ages ,and matrix isstoredatamemory
address(startingatafictitious20001000valueinthisexample)anddivisiblebyfour
(eachvariablestoresafour-bytevalue),that counter 'sfour-bytevalueisstoredat
this address, and that each of the ages and matrix four-byte memory locations
stores the 32-bit address of its respective array (64-bit addresses would most likely
be used on 64-bit JVMs). Also, a one-dimensional array is stored as a list of val-
ues,whereasatwo-dimensionalarrayisstoredasaone-dimensionalrowarrayofad-
dresses,whereeachaddressidentifiesaone-dimensionalcolumnarrayofvaluesfor
that row.
Although Figure 1-6 implies that array addresses are stored in ages and matrix ,
which equates references with addresses, a Java implementation might equate ref-
erences with handles (integer values that identify slots in a list). This alternative is
presented in Figure 1-7 for ages and its referenced array.
 
Search WWH ::




Custom Search