CS345 – Event-driven Programming

Slides:



Advertisements
Similar presentations
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Advertisements

Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Developing a Simple Graphical User Interface (GUI)
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.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
CS-1030 Dr. Mark L. Hornick 1 Pointers And Dynamic Memory.
Memory allocation CSE 2451 Matt Boggus. sizeof The sizeof unary operator will return the number of bytes reserved for a variable or data type. Determine:
Informática II Prof. Dr. Gustavo Patiño MJ
Client Side Programming Using Java Applet Outcomes: You will be expected to know: – Java Applets and HTML file; –bytecode and platform independent programs;
Figure 2.8 Compiler phases Compiling. Figure 2.9 Object module Linking.
Run-Time Storage Organization
Software GCSE COMPUTING.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Computer Science and Software Engineering University of Wisconsin - Platteville 2. Pointer Yan Shi CS/SE2630 Lecture Notes.
Basic Semantics Associating meaning with language entities.
CS350 – Windows Programming Formerly and more properly named: Event Driven Programming Dr. Randy Ribler.
Pointers OVERVIEW.
CPSC 252 Dynamic Memory Allocation Page 1 Dynamic memory allocation Our first IntVector class has some serious limitations the capacity is fixed at MAX_SIZE.
Dynamic Memory Allocation. Domain A subset of the total domain name space. A domain represents a level of the hierarchy in the Domain Name Space, and.
Object-Oriented Programming in C++
CS140: Intro to CS An Overview of Programming in C (part 3) by Erin Chambers.
Object Oriented Programming.  Interface  Event Handling.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 3: Process-Concept.
1 9/6/05CS360 Windows Programming CS360 Windows Programming.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
1 Lecture07: Memory Model 5/2/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
C LANGUAGE Characteristics of C · Small size
Fall 2004CS-183 Dr. Mark L. Hornick 1 C++ Arrays C++ (like Java) supports the concept of collections – mechanisms to sort and manipulate many instances.
Smart Pointers. Dumb Pointers Pointers Necessary – Dynamic memory – Sharing memory.
Dynamic Memory Management & Static Class Members Lecture No 7 Object Oriented Programming COMSATS Institute of Information Technology.
XP New Perspectives on Microsoft Windows XP Tutorial 1 1 Microsoft Windows XP Creating a Web Site Tutorial 1.
(More) Event handling. Input and Windowed-OS’s Windowed OS’s (Windows, OSX, GUI-linux’s) send messages (events) when the user does something “on” the.
Object Lifetime and Pointers
Processes and threads.
Process concept.
Protecting Memory What is there to protect in memory?
Introduction to Event-Driven Programming
Protecting Memory What is there to protect in memory?
objects CIS 421 Kutztown University
Chapter 3: Processes Source & Copyright: Operating System Concepts, Silberschatz, Galvin and Gagne.
Lesson 1: Buttons and Events – 12/18
Computer Programming and Basic Software Engineering 9 Building Graphical User Interface Developing a Simple Graphical User Interface (GUI)
Event Driven Programming
Dynamic Memory Allocation
CSC 253 Lecture 8.
CMSC 341 Prof. Michael Neary
Lecture 4: Process Memory Layout
Lecture 2: Processes Part 1
Introduction to Computing Using Java
CSC 253 Lecture 8.
Smart Pointers.
WEB PROGRAMMING JavaScript.
Pointers, Dynamic Data, and Reference Types
Dynamic Memory A whole heap of fun….
.Net Framework Details Imran Rashid CTO at ManiWeber Technologies.
Destructor CSCE 121 J. Michael Moore.
Chapter 3: Processes.
Destructor CSCE 121.
C Programming Lecture-8 Pointers and Memory Management
List Allocation and Garbage Collection
Event loops.
Pointers, Dynamic Data, and Reference Types
Automating Memory Management
Run-time environments
SPL – PS2 C++ Memory Handling.
Presentation transcript:

CS345 – Event-driven Programming Dr. Randy Ribler

Who’s in charge here? The Computer The User Many text-based console applications Computer says: “Enter username: “ Choices Enter a username Stop the program The User Event-driven/Graphical applications Computer responds to what the user does (events): Click a button Type a command Drag an icon

Event-driven Programming Desktop Programming Windows Programming X Window Programming (linux) Mobile Programming Android Programming iPhone Programming Web Programming ASP.NET JavaScript

Events (Messages) Mouse Clicks Mouse Movements Keyboard events (a character is pressed) Timer events (timer expires) Windows Events (e.g., a window gets/loses focus) System events (e.g., system shutdown)

Events are Described in Messages Messages have a unique identifier (message number) Message can carry parameters – for example: Cursor coordinates on a mouse click The object that caused the message to be sent The character that was typed The mouse button that was pressed

Messages Enter a Message Queue Third Message Second Message First Message Are Processed by a Message Loop

Message Loop While the program is still running (no quit message) Read a message from the message queue Decode the message Invoke the functions that have been associated with that message

Associating Functions with Messages C/C++ Function Pointers Point to functions called “callbacks” C# Delegates Safer types of function pointers

Function Pointers in C++ Functions that return pointers A function that returns a char* char* functionThatReturnsAPointer(int x); Pointers to functions A pointer to a function that returns a char* char* (*ptrName)(int x);

Memory Management in C++ Automatic variables are allocated on the run-time stack class Car { private: int year_; float mileage_; }; int x = 10; Car myCar; myCar.mileage_ 112000 myCar.year_ 2001 x 10 Return Address 0xabcdef04

Dynamically Allocated Memory in C++ Dynamically allocated memory in C++ is allocated from the “heap.” int x = 10; Car myCar; Car* ptr = new Car(); ptr 0x12341234 myCar.mileage_ 112000 myCar.year_ 2001 x 10 Return Address 0xabcdef04 The memory that stores the data member for the dynamically allocated car comes from the “heap,” and must be explicitly deallocated.

The Stack and the HeaP <allocated> <unallocated> ptr 0x12341234 myCar.mileage_ 112000 myCar.year_ 2001 x 10 Return Address 0xabcdef04

.Net Introduces “Managed Memory” Managed Memory is memory that is “Garbage Collected” Garbage Collected Memory is allocated with new, but does not need to be explicitly deallocated. A separate heap is maintained for garbage collected memory. A special kind of pointer is used to point to garbage collected memory. These pointers are called “handles.” The Garbage Collection Process Periodically, mark all the memory that is referenced by handles. All other memory on the garbage collected heap is deallocated. Memory in the garbage collected heap might be “compacted” to make all the allocated memory contiguous. This might require changing handle values.

Handles in C++/CLI There are two class types in C++/CLI Conventional Classes Can be automatically allocated on the stack Can be dynamically allocated from the standard heap using “new” Reference Classes Can only be allocated with gcnew Use handles to point to them Use garbage-collected memory to store them.

Conventional class in C++/CLI class Car { // : public: int myPublicDataMember_; }; int main() Car myCar; // myCar.myPublicDataMember is on the stack. Car* ptr = new Car(); // ptr->myPublicDataMember is on the heap. }

Reference class in C++/CLI Ref class RCar { // : public: int myPublicDataMember_; }; int main() Rcar^ myCar; // myCar.myPublicDataMember does not exist! myCar= gcnew Car(); // myCar->myPublicDataMember is on the gc heap. }