Computer Science 1037A/B Lecture Notes - Lecture 8: Memory Management, Dynamic Array, Memory Leak

7 views2 pages

Document Summary

Variables may be created and destroyed while a program is running. If you are writing a program and you do not know how many variables you should define upfront, then the program should create its own variables on the fly . This is called dynamic memory allocation and is only possible through the use of pointers. Can allocate storage for a variable while program is running. Uses new operator to allocate memory double *dptr; dptr = new double; This statement is requesting that the computer allocate enough memory for a new double variable new returns address of memory location. Can also use new to allocate array arrayptr = new double[25]; Program may terminate if there is not sufficient memory. Can then use [ ] or pointer arithmetic to access array. Every call to new allocates storage from a special area of the program"s memory called the heap.

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