This preview shows pages 1–2. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: COMP 250 Winter 2010 lecture 3 memory addresses, insertion sort January 11, 2010 In COMP 202, you learned about primitive types vs. reference types in Java. You think of a variable that is a primitive type as naming a particular set of bytes in memory, and the type of the variable says how the contents of those bytes should be interpreted. 1 You also were told in COMP 202 that different primitive types in Java use a different number of bits, and hence a different number of bytes where we recall that a byte is just a grouping of 8 bits: (boolean 2 , byte, char, short, int, long, float, double use 1,1,2,2,4,8,4,8, bytes respectively). Variables that are reference types are quite different. A reference variable also names a particular set of bytes in memory, but these bytes hold the address of an object. Thus, both primitive and reference variables name a particular set of bytes in memory, and these bytes are said to start at a particular address. In the following I will tell you slightly more about these memory addresses, which are probably not what most of you are thinking they are. Memory addresses Most computers that you will work with have either a 32 bit or 64 bit address space. An address is just a number, so we are talking about numbers from 0 to 2 32- 1 (in the case of 32 bits) or 0 to 2 64- 1 (in the case of 64 bit). For today, lets just say we have 32 bit addresses. Each address indexes one byte (8 bits) of memory. Such a byte can hold a piece of an instruction or a piece of data, that is, every instruction or data element is ultimately coded in binary and partitioned into bytes, and each of these bytes must have an address (a number from 0 to 2 32- 1) so that the program can refer to this byte (i.e. the byte at address x where x is a 32 bit number). It may surprise you to learn that these byte addresses do not refer to physical locations in the computers memory hardware (RAM, or hard disk, etc). Rather, when the computer uses such an address to find the physical location of the bytes making up an instruction or a data element in a problem, the computer must map these program addresses to physical addresses in the memory hardware....
View Full Document