Computer Memory, Variables, Variable Types, Arrays and Structures

by Herbert J. Bernstein

© Copyright 1999, Herbert J. Bernstein

The memory of a computer is organized into a regular pattern of containers for information. These containers for information are called "words". Each one has a numeric address and each one is the same size as each of the others. For most applications, it is inconvenient to refer to portions of memory by their numeric addresses, so programming languages allow us to allocate portions of memory by name. When we store information in the memory of a computer we need to decide on how much we need for various purposes and on how it will be organized. Programming languages provide mechanism for "types" of information in memory. They also provide mechanisms to identify repetitive arrays of items of the same type and to aggregate possibly heterogeneous types under a common name.

Conceptually the memory in a computer is very much like building lots laid out by lot number on a map of the streets of a city before any houses have been built.

 

Each lot on the map has a sequential number along some street with the streets themselves numbered sequentially. Each lot is the same size, say 20’ by 100’.

Now suppose people buy some of the lots and build houses. Suppose a developer takes the first 4 lots (1302-1308 51st Street) and builds an apartment building, calling it the "Park Arms". Suppose Mr. Jones and Ms. Smith each decide to build big houses, a ranch and a colonial, respectively, which span two lots each (1310-1312 and 1318-1320), and that Mr. Green and Mrs. Brown each decide to build a similar modest one-lot houses (1314 and 1316). The lots still have their numbers, so that the post-office can deliver mail, but people know the buildings by the appropriate names, "The Park Arms", the "Jones" ranch, the "Brown" house, the "Green" house and the "Smith" colonial.

In working with the memory of a computer, we do very much the same thing, we assemble the words that we need to hold the information we are working with into aggregates of the appropriate "type". Sometimes we need several words, sometimes just a couple, and sometimes just one. Different styles of houses, such as colonials and ranches, may use the space of a building lot differently. In a computer, we may decide to uses portions of the spaces provided by the words differently. In a computer, the combination of the size of the space we reserve and the way in which we use that space defines a "type" of storage.

Just as we make the distinction between two-lot colonial houses as a type of house and the particular two-lot colonial that Ms. Smith built in our hypothetical city, we distinguish the abstract types of storage allocation in a computer from the particular layouts of data we establish using those types. A type in a computer language is like a blueprint for builidng houses.

It may be conveneint to refer to buildings by names that help us remember who lives there. In using computer memory, can be helpful to refer to allocated portions of computer memory by names that help us remember the uses to which we are putting those portions of storage. In computing we call such names "variable" names.

A house has rooms into which we may cram only a certain amount of furniture. The words in a computer have a certain capacity, given in "bits", "nibbles", "characters", "bytes", "octets" "half-words" and other terms intended to convey a sense of smaller or larger portions of a word.

On modern computers, all the units of storage are effectively given in terms of "bits". A bit is a portion of memory which can hold either a "0" or a "1". The other terms mentioned above gone through historic changes and are likely to change again. Different computer manufacturers favored different numbers of bits in, say, a byte. At present, for the most popular desk-top computers and workstations, there is considerable agreement on the following sizes:

Portion of word

Number of bits

   

nibble

4

character

8 or 16

byte

8

octet

8

half-word

16

word

32

The ambiguity on the size of characters is because we are in a time of transition to richer and more complex character sets for which the limit of 256 characters imposed by an 8-bit character size is inappropriate. We may also be starting on a transition to 64-bit words. Time will tell.

Now let us return to our analogy to street maps. The apartment house, the "Park Arms", has one address (1302-51st Street), which refers to many apartments, each of which has an address (an apartment number) within the apartment house. Similar concepts are available in organizing computer memory. An "array" is a sequence of allocated locations in memory, each of which is of the same type. We locate items within an array by their "indices". An "index" serves a similar purpose to the number of an apartment along a floor, or the floor number, or the building number within an apartment complex. In a computer an array may be organized around one, two, three or more indices, which of which is allowed to vary within a predermined range called a "dimension".

Again returning to our analogy to street maps, consider the possibility that someone might decide to buy several blocks of a neighborhood and make a subdivision. Within that subdivision, we could have a new street number system, and either a uniform type of house or a variety of types of houses. In organizing computer memory we can do much the same thing with "structures". A "structure" is a heterogeneous combination of variable types and arrays of types composing one agregate type. Items within the structure are identified by the the name of the structure and the name of a particular component.



Last Updated on 11 October 1999
By Herbert J. Bernstein
Email:
yaya@bernstein-plus-sons.com