Memory Addresses


Imagine main memory as a series of seemingly endless boxes organized into groups of eight. Each box holds a zero or one. Each group of eight boxes (1 byte) is assigned a unique number called a memory address , as shown in Figure 1-10. It is very important to keep this in mind as you learn about data structures; otherwise , you can easily become confused .

click to expand
Figure 1-10: The memory address of the first byte is used to reference all bytes reserved for an abstract data type.

A memory address is indirectly or directly used within a program to access all eight boxes. For example, say your program tells the computer that you want to copy data stored in memory location 423 ”that is, the box whose address is 423. The computer goes to thatmemory location and copies the data (zero or one) from box 423 and copies data from the next seven boxes. Those next seven boxes don t have a memory address. You could say that those seven boxes share the memory address of box 423.

Real Memory Addresses

Memory addresses are represented so far throughout this chapter as a decimal value, such as box 423. In reality, memory addresses are a 32-bit or 64-bit number, depending on the computer s operating system, and are represented as a hexadecimal value.

Hexadecimal is a numbering system similar to the decimal and binary numbering systems. That is, hexadecimal values are used to count and they are used in arithmetic. The hexadecimal numbering system has 16 digits from 0 through 9 andAthrough F, which represents 10 through 15. Here is howmemory address 258,425,506 is represented in hexadecimal notation 0x0F6742A2.

Abstract Data Types and Memory Addresses

Previously in this chapter you learned that you reservememory for data by using an abstract data type. Some abstract data types reserve memory in a size that is greater than 1 byte. For example, the short abstract data type in Java reserves 2 bytes of memory.

Since each byte of memory has its own memory address, you might assume a short has two memory addresses because it uses 2 bytes of memory. That s not the case. The computer uses the memory address of the first byte to reference any abstract data type that reserves multiple bytes of memory.

Let s say that space was reserved in memory for a short abstract data type (see Figure 1-10). Two memory locations are reserved, memory addresses 400 and 401. However, only memory address 400 is used to reference the short . The computer automatically knows that the value stored in memory address 401 is part of the value stored in memory address 400 because the space was reserved using an short abstract data type. Therefore, the computer copies all the bits frommemory address 400 and all the bits frommemory address 401 whenever a request is made by the program to copy the integer stored at memory address 400.




Data Structures Demystified
Data Structures Demystified (Demystified)
ISBN: 0072253592
EAN: 2147483647
Year: 2006
Pages: 90

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net