comp 401 memory representation of primitive values and objects

18
COMP 401 MEMORY REPRESENTATION OF PRIMITIVE VALUES AND OBJECTS Instructor: Prasun Dewan

Upload: lawrence-mckenzie

Post on 31-Dec-2015

43 views

Category:

Documents


2 download

DESCRIPTION

Comp 401 Memory Representation of Primitive Values and Objects. Instructor: Prasun Dewan. Storing Primitive Values and Variables. int i = 5;. address. variables. memory. 16. 5. 5. Memory Block. 32 bits. Memory blocks are of the same size. 52. int i. 32 bits. - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

Comp 401Memory Representation of Primitive Values and ObjectsInstructor: Prasun Dewan

#Storing Primitive Values and Variablesvariablesmemory516addressint i = 5;int i525Memory BlockMemory blocks are of the same size32 bits32 bits

#Storing Primitive Values and Variablesvariablesmemory5.58addressdouble d = 5.5;double d485.5Memory BlockMemory blocks are of the same size64 bits64 bitsdouble e = d;80double e5.5

#Storing Primitive ValuesValues and variables of same type take same amount of fixed storage.The storage consists of one or more consecutive memory words that together form a memory block.Values and variables of different types may take different storage.

#Storing ObjectsCan we assign all variables and objects of the same object type the same sized memory block?No: A variable can be assigned instances of different classes.Different instances of the same class can take different amount of space.

#Instance-Specific Structurenew AnAnotherLine(new APolarPoint (14.01, 0.78), 20, 20)AnAnotherLineAPolarPointintintlocationheightwidthdoubleangleradiusdouble

#Instance-Specific StructureAnAnotherLineACartesianPointintintlocationheightwidthintxyintnew AnAnotherLine(new ACartesianPoint (10, 10), 20, 20)Structures of instances of same class can be different!

#Storing Object Values and VariablesvariablesmemoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@8850100public class ACartesianPoint implements Point {int xint y;}Instance variables stored in memoryPoint p1528Address of object copied to blockMemory blocks are of different size!Object variables are pointers to memory blocks

#Assignment of Object VariablesvariablesmemoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@8850100Point p2 = p1;Point p1528Point p2568ACartesianPoint@8p2p1

#Assignment of Object VariablesvariablesmemoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@8850100Point p2 = p1;Point p1528Point [email protected](100);100p2.getX(); 1008

#Assignment of Object VariablesvariablesmemoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@8850100Point p2 = p1;Point p1528Point [email protected](100);100p2.getX(); 1008Point p1 = new ACartesianPoint(150,75); ACartesianPoint@[email protected](); 100

##Extra Slides#Storing Primitive Values and Variablesvariablesmemory516addressint i = 5;int i525Memory BlockMemory blocks are of the same size32 bits32 bits#Storing Primitive Values and Variablesvariablesmemory5.58addressdouble i = 5.5;double d485.5Memory BlockMemory blocks are of the same size64 bits64 bitsdouble e = d;80double e5.55.5#Storing Object Values and VariablesvariablesmemoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@8850100public class ACartesianPoint implements Point {int xint y;}Instance variables stored in memoryPoint p1528Address of object copied to blockMemory blocks are of different size!Object variables are pointers to memory blocks#Assignment of Object VariablesvariablesmemoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@8850100Point p2 = p1;Point p1528Point p2568#Assignment of Object VariablesACartesianPoint@8p2p1#