Slide 1Storing Primitive Values and VariablesStoring Primitive Values and VariablesStoring Primitive ValuesStoring ObjectsInstance-Specific StructureInstance-Specific StructureStoring Object Values and VariablesAssignment of Object VariablesAssignment of Object VariablesAssignment of Object VariablesSlide 12Extra SlidesStoring Primitive Values and VariablesStoring Primitive Values and VariablesStoring Object Values and VariablesAssignment of Object VariablesAssignment of Object VariablesCOMP 401MEMORY REPRESENTATION OF PRIMITIVE VALUES AND OBJECTSInstructor: Prasun Dewan2STORING PRIMITIVE VALUES AND VARIABLESvariables memory516addressint i = 5;int i525Memory BlockMemory blocks are of the same size32 bits32 bits3STORING PRIMITIVE VALUES AND VARIABLESvariables memory5.58addressdouble d = 5.5;double d485.5Memory BlockMemory blocks are of the same size64 bits64 bitsdouble e = d;80 double e5.54STORING 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.5STORING 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.6INSTANCE-SPECIFIC STRUCTUREnew AnAnotherLine(new APolarPoint (14.01, 0.78), 20, 20)AnAnotherLineAPolarPointintintlocationheightwidthdoubleangleradiusdouble7INSTANCE-SPECIFIC STRUCTUREAnAnotherLineACartesianPointintintlocationheightwidthintxyintnew AnAnotherLine(new ACartesianPoint (10, 10), 20, 20)Structures of instances of same class can be different!8STORING OBJECT VALUES AND VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100public class ACartesianPoint implements Point {int xint y;…}Instance variables stored in memoryPoint p152 8Address of object copied to blockMemory blocks are of different size!Object variables are pointers to memory blocks9ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p2568ACartesianPoint@8p2 p110ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p2568ACartesianPoint@8p2 p1p1.setX(100);100p2.getX(); 100811ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p256ACartesianPoint@8p2 p1p1.setX(100);100p2.getX(); 1008Point p1 = new ACartesianPoint(150,75); ACartesianPoint@7676 [email protected](); 1001213EXTRA SLIDES14STORING PRIMITIVE VALUES AND VARIABLESvariables memory516addressint i = 5;int i52 5Memory BlockMemory blocks are of the same size32 bits32 bits15STORING PRIMITIVE VALUES AND VARIABLESvariables memory5.58addressdouble i = 5.5;double d485.5Memory BlockMemory blocks are of the same size64 bits64 bitsdouble e = d;80 double e5.55.516STORING OBJECT VALUES AND VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100public class ACartesianPoint implements Point {int xint y;…}Instance variables stored in memoryPoint p152 8Address of object copied to blockMemory blocks are of different size!Object variables are pointers to memory blocks17ASSIGNMENT OF OBJECT VARIABLESvariables memoryaddressPoint p1 = new ACartesianPoint(50,100); ACartesianPoint@88 50100Point p2 = p1;Point p152 8Point p256 818ASSIGNMENT OF OBJECT VARIABLESACartesianPoint@8p2
View Full Document