csci261
play

CSCI261 Lecture 27: Events, Interrupts & Event Handling Memory, - PowerPoint PPT Presentation

CSCI261 Lecture 27: Events, Interrupts & Event Handling Memory, Stack, Stack Frames, The Heap Attribution: http://123rf.com keypress Keyboard Interface (Serial USB) Bus CPU Operating System Application keypress Keyboard Interface


  1. CSCI261 Lecture 27: Events, Interrupts & Event Handling Memory, Stack, Stack Frames, The Heap

  2. Attribution: http://123rf.com

  3. keypress Keyboard Interface (Serial USB) Bus CPU Operating System Application

  4. keypress Keyboard Interface (Serial USB) electrical signal Bus hardware “interrupt” CPU Operating System “oooh, a keypress event” event handler Application

  5. Event Loop Modern graphical programs wait in an infinite “event loop,” waiting for some events to happen. update(); draw(); update(); draw(); update(); draw();

  6. Event Handling When an event occurs, call a function. an “event handler”

  7. OF Event Handlers • keyPressed • keyReleased • mouseMoved • mouseDragged • mousePressed • mouseReleased • windowResized

  8. Memory & Functions • Stack • Stack Frames • The Heap

  9. The Stack LIFO

  10. ? int main() { 5 int x = 2; 2 int y = 5; int z = sum(x, y); }

  11. int sum(int x, int y) { return x + y; } 5 local variables 2 ? int main() { 5 int x = 2; 2 int y = 5; int z = sum(x, y); }

  12. int sum(int x, int y) { return x + y; } 7 stack frame 5 2 ? int main() { 5 int x = 2; 2 int y = 5; int z = sum(x, y); }

  13. int sum(int x, int y) { return x + y; } 5 int main() { 5 int x = 2; 2 int y = 5; int z = sum(x, y); }

  14. Stack Frames One aspect of where “scope” comes from. Contains parameter values, local variable values, and “bookkeeping” information. Function call? New stack frame. Function return? Pop the entire stack frame.

  15. Problem Things created within functions “go away” after the function returns... ... and sometimes, we want those “things” to stick around after the function returns.

  16. Problem Storing too much on the stack can cause “stack overflow” http://stackoverflow.com

  17. Problem In many cases, we do not know how much memory to allocate at compile time. We must allocate memory dynamically, during run-time.

  18. Is there another place we can store stuff?

  19. The Heap aka “the free store” A pool of unused memory, for your programs to use.

  20. Stack vs. Heap organized unorganized efficient less efficient accessed “directly” (but we don’t care) storage of “things” dynamic storage known in advance and more... and more...

  21. Heap The exact location of things on the heap is not known in advance. How can your code access data whose locations are not known in advance?

  22. How can your code access data whose locations are not known in advance? Pointers (to be continued)

  23. Homework Choose final project partners and send your instructor an email.

More recommend