CSCI261
Lecture 27: Events, Interrupts & Event Handling Memory, Stack, Stack Frames, The Heap
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
Lecture 27: Events, Interrupts & Event Handling Memory, Stack, Stack Frames, The Heap
Attribution: http://123rf.com
Keyboard Interface (Serial USB) Bus CPU Operating System Application
keypress
Keyboard Interface (Serial USB) Bus CPU Operating System Application
keypress electrical signal hardware “interrupt”
“oooh, a keypress event” event handler
Modern graphical programs wait in an infinite “event loop,” waiting for some events to happen. update(); draw(); update(); draw(); update(); draw();
When an event occurs, call a function. an “event handler”
LIFO
int main() { int x = 2; int y = 5; int z = sum(x, y); }
2 5
?
int main() { int x = 2; int y = 5; int z = sum(x, y); }
2 5
?
int sum(int x, int y) { return x + y; }
2 5
local variables
int main() { int x = 2; int y = 5; int z = sum(x, y); }
2 5
?
int sum(int x, int y) { return x + y; }
2 5 7
stack frame
int main() { int x = 2; int y = 5; int z = sum(x, y); }
2 5
int sum(int x, int y) { return x + y; }
5
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.
Things created within functions “go away” after the function returns... ... and sometimes, we want those “things” to stick around after the function returns.
Storing too much on the stack can cause “stack overflow” http://stackoverflow.com
In many cases, we do not know how much memory to allocate at compile time. We must allocate memory dynamically, during run-time.
Is there another place we can store stuff?
A pool of unused memory, for your programs to use.
aka “the free store”
efficient accessed “directly” storage of “things” known in advance and more... unorganized less efficient (but we don’t care) dynamic storage and more...
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?
How can your code access data whose locations are not known in advance?
(to be continued)
Choose final project partners and send your instructor an email.