Class Notes (1,100,000)
CA (630,000)
UW (20,000)
CS (1,000)
CS138 (10)
Lecture 7

CS138 Lecture Notes - Lecture 7: Multiset, Multimap

Computer Science
Course Code
Michael Godfrey

This preview shows half of the first page. to view the full 3 pages of the document.
Data Lecture 7
January 29, 2013
Static & Dynamic Memory Allocation
Memory/storage for your variables comes from one of two possible places
1. RUN-TIME STACK handles automated allocation & de-allocation for parameters and local
variables as procedures are called
This storage automatically disappears when the procedure finishes executing
2. FREESTORE / THE HEAP handles all programmatic requests for storage via MALLOC and
NEW (for objects, structs, and anything else C++ style)
Program must return this storage when done with it via FREE or DELETE
o Ballon *b = new Balloon;
Pointer b is stored on stack
Object it points to is on heap
struct Node {
string val;
Node* next;
int main(...) {
Node *p; // p is pointer
p = new Node;
p -> val = "first";
p -> next = NULL;
Node* q,r; // q is pointer, r is NODE
r.val = "flurble";
q = new Node;
q -> next = p;
q -> val = "second";
Node* s = new Node; // s is pointer
s -> val = "third";
s -> next = q;
Node temp=s;
while (NULL != temp) {
cout<<temp -> val << endl;
temp = temp-> next;
You're Reading a Preview

Unlock to view full version