COMP 401 MEMORY REPRESENTATION OF PRIMITIVE VALUES AND
- Slides: 18
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 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 n tio a c APolar. Point radius lo An. Another. Line width he ig h t int new An. Another. Line(new APolar. Point (14. 01, 0. 78), 20) 6
INSTANCE-SPECIFIC STRUCTURE int x n tio a c ACartesian. Point y lo An. Another. Line width he ig h t int new An. Another. Line(new ACartesian. Point (10, 10), 20) Structures of instances of same class can be different! 7
STORING OBJECT VALUES AND VARIABLES public class ACartesian. Point implements Point { int x int y; … } address variables memory 8 ACartesian. Point@8 50 100 Instance variables stored in memory Point p 1 = new ACartesian. Point(50, 100); 52 Memory blocks are of different size! Point p 1 8 Address of object copied to block Object variables are pointers to memory blocks 8
ASSIGNMENT OF OBJECT VARIABLES Point p 1 = new address variables memory 8 ACartesian. Point@8 50 100 52 Point p 1 8 56 Point p 2 ACartesian. Point(50, 100); Point p 2 = p 1; p 1 ACartesian. Point@8 9
ASSIGNMENT OF OBJECT VARIABLES Point p 1 = new address variables memory 8 ACartesian. Point@8 100 50 100 52 Point p 1 8 56 Point p 2 8 ACartesian. Point(50, 100); Point p 2 = p 1; p 1. set. X(100); p 2. get. X(); p 2 100 p 1 ACartesian. Point@8 10
ASSIGNMENT OF OBJECT VARIABLES Point p 1 = new address variables memory 8 ACartesian. Point@8 100 50 100 52 Point p 1 76 8 56 Point p 2 8 76 ACartesian. Point@76 150 50 75 ACartesian. Point(50, 100); Point p 2 = p 1; p 1. set. X(100); p 2. get. X(); 100 Point p 1 = new ACartesian. Point(150, 75); p 2. get. X(); p 2 100 p 1 ACartesian. Point@8 ACartesian. Point@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 48 double d 5. 5 80 double e 5. 5 15
STORING OBJECT VALUES AND VARIABLES public class ACartesian. Point implements Point { int x int y; … } address variables memory 8 ACartesian. Point@8 50 100 Instance variables stored in memory Point p 1 = new ACartesian. Point(50, 100); 52 Memory blocks are of different size! Point p 1 8 Address of object copied to block Object variables are pointers to memory blocks 16
ASSIGNMENT OF OBJECT VARIABLES Point p 1 = new address variables memory 8 ACartesian. Point@8 50 100 52 Point p 1 8 56 Point p 2 8 ACartesian. Point(50, 100); Point p 2 = p 1; 17
ASSIGNMENT OF OBJECT VARIABLES p 2 p 1 ACartesian. Point@8 18
- Comp 401
- Data structure classification
- Classification of data structures
- Data representation in memory bit
- Memory representation of array
- Data representation in memory
- Data representation in computer organization
- Machiavellian personality
- Terminal values and instrumental values
- Internal memory and external memory
- Primary memory and secondary memory
- Virtual memory
- Western values vs eastern values
- A bit can have only two possible values one and
- Concepts of human values
- Lsp 401
- Svartpilen 401 dyno
- Cse401
- Ge 401