C OMP 401 M EMORY R EPRESENTATION OF P RIMITIVE V ALUES AND O BJECTS Instructor: Prasun Dewan.

Slides:



Advertisements
Similar presentations
E LEMENTARY D ATA STRUCTURES. A RRAYS Sequence of elements of similar type. Elements are selected by integer subscripts. For example, signs: array[37:239]
Advertisements

Chapter 19 Vectors, templates, and exceptions Bjarne Stroustrup
Copyright © 2003 Pearson Education, Inc. Slide 1.
CISC Data Structures Ben Perry University of Delaware Summer 2011.
Constructor. 2 constructor The main use of constructors is to initialize objects. A constructor is a special member function, whose name is same as class.
Pointers Prasun Dewan Comp 114.
1 Structures. 2 User-Defined Types C provides facilities to define one’s own types. These may be a composite of basic types ( int, double, etc) and other.
Chapter 9 Pointers and Dynamic Arrays. Overview 9.1 Pointers 9.2 Dynamic Arrays.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
Pointers & Dynamic Memory Allocation Mugurel Ionu Andreica Spring 2012.
Enumerated data type & typedef. Enumerated Data Type An enumeration consists of a set of named integer constants. An enumeration type declaration gives.
ENUMERATED, typedef. ENUMERATED DATA TYPES An enumeration consists of a set of named integer constants. An enumeration type declaration gives the name.
C OMP 401 C LASS S TATE Instructor: Prasun Dewan.
C OMP 401 O BJECTS Instructor: Prasun Dewan 2 C OMPUTER VS. P ROGRAM M ODEL Processor Compiler Program (source code)
Arrays. Memory organization Table at right shows 16 bytes, each consisting of 8 bits Each byte has an address, shown in the column to the left
C OMP 110 L OAN C ASE S TUDY Instructor: Jason Carter.
C OMP 110 O BJECTS Instructor: Jason Carter. 2 C OMPUTER VS. P ROGRAM M ODEL Processor Compiler Program (source code)
J AVA AND V ARIABLES. O VERVIEW Declaring a Variable Primitive Types Java Keywords Reference Variables Object Declaration and Assignment Objects and Garbage.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
1 Engineering Problem Solving With C++ An Object Based Approach Fundamental Concepts Chapter 1 Engineering Problem Solving.
COMS W3156: Software Engineering, Fall 2001 Lecture #20: C, continued Janak J Parekh
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
Primitive Values Vs Objects Wrapper Classes Memory Representation of Primitive Values Vs Objects –Pointers Equal Vs == Sharing of Objects Garbage Collection.
Disk Storage Copyright © 2004 Pearson Education, Inc.
Object Oriented Programming Concepts OOP – reasoning about a program as a set of objects rather than as a set of actions Object – a programming entity.
C OMP 401 C LASS S TATE Instructor: Prasun Dewan.
Values, variables and types © Allan C. Milne v
OBJECTIVES  Explain why a computer represents data in the form of binary  Explain the terms related to data storage: bit, byte, character, word  Calculate.
C OMP 401: C ONSTRUCTORS AND P OINTERS Instructor: Prasun Dewan (FB 150,
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
Pointers & Dynamic Arrays Shinta P.
Array in C++ / review. An array contains multiple objects of identical types stored sequentially in memory. The individual objects in an array, referred.
Chapter 7 Formatted input and output. 7.1 introduction Tax: This result is correct; but it would be better Maybe as $13, Make formatting.
CSC 107 – Programming For Science. Today’s Goal  When lecture over, start understanding pointers  What a pointer is and what it is not  Why pointers.
CSC 107 – Programming For Science. Today’s Goal  When lecture over, start understanding pointers  What a pointer is and what it is not  Why pointers.
Information Systems Engineering
C OMP 401 A DVANCED G ENERICS Instructor: Prasun Dewan.
Chapter 11 – Pointer Variables. Declaring a Pointer Variable u Declared with data type, * and identifier type* pointer_variable; u * follows data type.
Sahar Mosleh California State University San MarcosPage 1 The Class String There is no primitive type for strings in Java The class String is a predefined.
C Programming Lecture 16 Pointers. Pointers b A pointer is simply a variable that, like other variables, provides a name for a location (address) in memory.
DATA STRUCTURE & ALGORITHMS Pointers & Structure.
Department of Electronic & Electrical Engineering Types and Memory Addresses Pointers & and * operators.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
POINTERS IN C. Introduction  A pointer is a variable that holds a memory address  This address is the location of another object (typically another.
A DVANCED P ROGRAMMING C HAPTER 4: I NTRODUCTION TO I NTRODUCTION TO C LASSES, O BJECTS, M ETHODS AND STRINGS Dr Shahriar Bijani Winter 2016.
Data Structures in C++ Pointers & Dynamic Arrays Shinta P.
CS 31 Discussion, Week 7 Faisal Alquaddoomi, Office Hours: BH 2432, W 4:30-6:30pm, F 12:30-1:30pm.
C OMP 401 C OPY : S HALLOW AND D EEP Instructor: Prasun Dewan.
Madhuri Gollu Id: 207. Agenda Agenda  Records with Variable Length Fields  Records with Repeating Fields  Variable Format Records  Records that do.
UNIT-II Topics to be covered Singly linked list Circular linked list
Pointers Data Structures CSI 312 CSI Dept. Dr. Yousef Qawqzeh.
Object Lifetime and Pointers
Engineering Problem Solving With C An Object Based Approach
Arrays Low level collections.
26 - File Systems.
Memberwise Assignment / Initialization
Basic notes on pointers in C
DATA HANDLING.
Comp 401 Metamorphosis: Casting vs. Conversion
Return by Reference CSCE 121 J. Michael Moore.
Arrays .
Storing Information Each memory cell stores a set number of bits (usually 8 bits, or one byte) (byte addressable)
Indirection.
Static is one of the modifiers that determine variable and method characteristics. The static modifier associates a variable or method with its class.
C Programming Pointers
Run-time environments
Introduction to Pointers
Presentation transcript:

C OMP 401 M EMORY R EPRESENTATION OF P RIMITIVE V ALUES AND O BJECTS Instructor: Prasun Dewan

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

3 S TORING P RIMITIVE V ALUES AND V ARIABLES variablesmemory address double d = 5.5; double d Memory Block Memory blocks are of the same size 64 bits double e = d; 80double e 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.

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.

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

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!

8 S TORING O BJECT V ALUES AND V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); 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

9 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); 100 Point p2 = p1; Point p1528 Point p256 8 p2p1

10 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); 100 Point p2 = p1; Point p1528 Point p256 8 p2p1 p1.setX(100); 100 p2.getX();  100 8

11 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); 100 Point p2 = p1; Point p1528 Point p256 p2p1 p1.setX(100); 100 p2.getX();  Point p1 = new ACartesianPoint(150,75); p2.getX();  100

12

13 E XTRA S LIDES

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

15 S TORING P RIMITIVE V ALUES AND V ARIABLES variablesmemory address double i = 5.5; double d Memory Block Memory blocks are of the same size 64 bits double e = d; 80double e 5.5

16 S TORING O BJECT V ALUES AND V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); 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

17 A SSIGNMENT OF O BJECT V ARIABLES variablesmemoryaddress Point p1 = new ACartesianPoint(50,100); 100 Point p2 = p1; Point p1528 Point p2568

18 A SSIGNMENT OF O BJECT V ARIABLES p2p1