COMP 401 MEMORY REPRESENTATION OF PRIMITIVE VALUES AND OBJECTS Instructor Prasun Dewan STORING PRIMITIVE VALUES AND VARIABLES int i 5 address variables 16 Memory Block Memory blocks are of the same size memory 5 32 bits 52 int i 32 bits 2 STORING PRIMITIVE VALUES AND VARIABLES double d 5 5 address variables 8 Memory Block Memory blocks are of the same size double e d memory 5 5 64 bits 64 bits 48 double d 80 double e 5 5 3 STORING PRIMITIVE VALUES Values 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 4 STORING OBJECTS Can 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 5 INSTANCE SPECIFIC STRUCTURE angle double double io t a AnAnotherLine n loc width he i gh t APolarPoint radius int int new AnAnotherLine new APolarPoint 14 01 0 78 20 20 6 INSTANCE SPECIFIC STRUCTURE int x io t a AnAnotherLine n loc width he i gh t ACartesianPoint int y int int new AnAnotherLine new ACartesianPoint 10 10 20 20 Structures of instances of same class can be different 7 STORING OBJECT VALUES AND VARIABLES public class ACartesianPoint implements Point int x int y address variables memory 8 ACartesianPoint 8 50 100 Instance variables stored in memory Point p1 new ACartesianPoint 50 100 52 Memory blocks are of different size Point p1 8 Address of object copied to block Object variables are pointers to memory blocks 8 ASSIGNMENT OF OBJECT VARIABLES Point p1 new ACartesianPoint 50 100 Point p2 p2 p1 address variables memory 8 ACartesianPoint 8 50 100 52 Point p1 8 56 Point p2 p1 ACartesianPoint 8 9 ASSIGNMENT OF OBJECT VARIABLES Point p1 new ACartesianPoint 50 100 Point p2 p1 p1 setX 100 p2 getX p2 address variables memory 8 ACartesianPoint 8 100 50 100 52 Point p1 8 56 Point p2 8 100 p1 ACartesianPoint 8 10 ASSIGNMENT OF OBJECT VARIABLES Point p1 new ACartesianPoint 50 100 Point p2 p1 p1 setX 100 p2 getX address variables memory 8 ACartesianPoint 8 100 50 100 52 Point p1 76 8 56 Point p2 8 76 ACartesianPoint 76 150 50 75 100 Point p1 new ACartesianPoint 150 75 p2 getX p2 100 p1 ACartesianPoint 8 ACartesianPoint 76 11 12 EXTRA SLIDES 13 STORING PRIMITIVE VALUES AND VARIABLES int i 5 address variables 16 Memory Block Memory blocks are of the same size memory 5 32 bits 52 int i 5 32 bits 14 STORING PRIMITIVE VALUES AND VARIABLES double i 5 5 address variables 8 Memory Block Memory blocks are of the same size double e d memory 5 5 64 bits 64 bits 48 double d 5 5 80 double e 5 5 15 STORING OBJECT VALUES AND VARIABLES public class ACartesianPoint implements Point int x int y address variables memory 8 ACartesianPoint 8 50 100 Instance variables stored in memory Point p1 new ACartesianPoint 50 100 52 Memory blocks are of different size Point p1 8 Address of object copied to block Object variables are pointers to memory blocks 16 ASSIGNMENT OF OBJECT VARIABLES Point p1 new ACartesianPoint 50 100 Point p2 p1 address variables memory 8 ACartesianPoint 8 50 100 52 Point p1 8 56 Point p2 8 17 ASSIGNMENT OF OBJECT VARIABLES p2 p1 ACartesianPoint 8 18
View Full Document
Unlocking...