Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.


9.2.1 Addresses

Every piece of data a program uses is stored somewhere in the computer's memory,and this includes the data contained in variables. So, when you assign one to the variable x you are actually storing one in the location reserved for x in the computer's memory. A location in memory is known as a memory address, and this is just a 32-bit number (so can be stored in a LONG variable). If you know the location of a variable's data then you can read the value and you can also change it.

To understand memory addresses, a good analogy is to think of memory as a road or street, each memory location as a post-box on a house, and each piece of data as a letter. If you were a postman you would need to know where to put your letters, and this information is given by the address of the post-box. As time goes by, each post-box is filled with different letters. This is like the value in a memory location (or variable) changing. To change the letters stored in your post-box, you tell your friends your address and they can send letters in and fill it. This is like letting some part of a program change your data by giving it the address of the data.

The next two diagrams illustrate this analogy. A letter contains an address which points to a particular house (or lot of mail) on a street.

       +-------+
       | Letter|
       |-------|
       |Address+----*
       +-------+     \
                      \
                       \
         +--------+ +---\----+ +--------+     +--------+
         | House  | | House  | | House  |     | House  |
Street:  |+------+| |+------+| |+------+| ... |+------+|
         || Mail || || Mail || || Mail ||     || Mail ||
         +========+ +========+ +========+     +========+

A pointer contains an address which points to a variable (or data) in memory.

       +-------+
       |Pointer|
       |-------|
       |Address+----*
       +-------+     \
                      \
                       \
         +--------+ +---\----+ +--------+     +--------+
         |Variable| |Variable| |Variable|     |Variable|
Memory:  |+------+| |+------+| |+------+| ... |+------+|
         || Data || || Data || || Data ||     || Data ||
         +========+ +========+ +========+     +========+


Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.