Download presentation
Presentation is loading. Please wait.
2
C OMP 401 M EMORY R EPRESENTATION OF P RIMITIVE V ALUES AND O BJECTS Instructor: Prasun Dewan
3
2 S TORING P RIMITIVE V ALUES AND V ARIABLES variablesmemory 516 address int i = 5; int i52 5 Memory Block Memory blocks are of the same size 32 bits
4
3 S TORING P RIMITIVE V ALUES AND V ARIABLES variablesmemory 5.5 8 address double d = 5.5; double d48 5.5 Memory Block Memory blocks are of the same size 64 bits double e = d; 80double e 5.5
5
4 S TORING P RIMITIVE V ALUES 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.
6
5 S TORING O BJECTS 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.
7
6 I NSTANCE -S PECIFIC S TRUCTURE new AnAnotherLine( new APolarPoint (14.01, 0.78), 20, 20) AnAnotherLine APolarPoint int location height width double angle radius double
8
7 I NSTANCE -S PECIFIC S TRUCTURE AnAnotherLine ACartesianPoint int location height width int x y new AnAnotherLine( new ACartesianPoint (10, 10), 20, 20) Structures of instances of same class can be different!
9
8 S TORING O BJECT V ALUES AND V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); ACartesianPoint@8850 100 public class ACartesianPoint implements Point { int x int y; … } Instance variables stored in memory Point p1528 Address of object copied to block Memory blocks are of different size! Object variables are pointers to memory blocks
10
9 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); ACartesianPoint@8850 100 Point p2 = p1; Point p1528 Point p256 8 ACartesianPoint@8 p2p1
11
10 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); ACartesianPoint@8850 100 Point p2 = p1; Point p1528 Point p256 8 ACartesianPoint@8 p2p1 p1.setX(100); 100 p2.getX(); 100 8
12
11 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); ACartesianPoint@8850 100 Point p2 = p1; Point p1528 Point p256 ACartesianPoint@8 p2p1 p1.setX(100); 100 p2.getX(); 100 8 Point p1 = new ACartesianPoint(150,75); ACartesianPoint@767650 75 150 76 ACartesianPoint@76 p2.getX(); 100
13
12
14
13 E XTRA S LIDES
15
14 S TORING P RIMITIVE V ALUES AND V ARIABLES variablesmemory 516 address int i = 5; int i525 Memory Block Memory blocks are of the same size 32 bits
16
15 S TORING P RIMITIVE V ALUES AND V ARIABLES variablesmemory 5.5 8 address double i = 5.5; double d48 5.5 Memory Block Memory blocks are of the same size 64 bits double e = d; 80double e 5.5
17
16 S TORING O BJECT V ALUES AND V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); ACartesianPoint@8850 100 public class ACartesianPoint implements Point { int x int y; … } Instance variables stored in memory Point p1528 Address of object copied to block Memory blocks are of different size! Object variables are pointers to memory blocks
18
17 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); ACartesianPoint@8850 100 Point p2 = p1; Point p1528 Point p2568
19
18 A SSIGNMENT OF O BJECT V ARIABLES ACartesianPoint@8 p2p1
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.