CMPT 225 Lecture Notes - Object Copying, Memory Leak

32 views3 pages

Document Summary

// copy contents over from old array for (int i = 0; i < n/2; i++) { arr[i] = old[i]; // however, old array is still sitting in free store! // have a memory leak (dun dun dun) (no auto garbage collection) delete [] old; // deallocates memory. // auto garbage collection has cost, because we don"t know when it"s going to happen. May be important, or not important, depending on program. arr[top] = elem; top++; Dynamic memory: the heap or the free store float mystack::peek() { return arr[top - 1]; // top is always next thing to insert. // pre: stack is non-empty use namespace std void pushtest(); void poptest(); int main() pushtest(); poptest(); cout << endl << endl; return 0; void pushtest()

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents