![]() |
| | #1 |
| Refugee Join Date: Aug 2001
Posts: 2,052
| Thanks -Chris
__________________ Please direct all complaints regarding this post to the nearest brick wall Have a nice day. |
| face_master is offline |
| | #2 |
| Registered User Join Date: Sep 2001
Posts: 156
| The heap is reserved for dynamic memory allocation needs of the program. It is an area apart from the program code and the stack. Typical C programs use the functions malloc and free to allocate and deallocate heap memory. C++ uses the new and delete operator. The new operatroe allocates the memory then calls the constructor to initialize it. The delete operator does all the necessary (hopefully) cleanup then the memory is made availible (deallocated) for reuse on the heap. To allocate an array of bytes on the stack The array is automatically deleted and its memory reclaimed when the array variable exits its scope. { const int BUFF_SIZE = 128; // Allocate on the frame char myCharArray[BUFF_SIZE]; int myIntArray[BUFF_SIZE]; // Reclaimed when exiting scope } To allocate an array of bytes (or any primitive data type) on the heap Use the new operator with the array syntax shown in this example: const int BUFF_SIZE = 128; // Allocate on the heap char* myCharArray = new char[BUFF_SIZE]; int* myIntArray = new int[BUFF_SIZE]; //Reclaimed with delete delete [] myCharArray; delete [] myIntArray; |
| Dang is offline |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Wiki FAQ | dwks | General Discussions | 192 | 04-29-2008 01:17 PM |
| Redirect FAQ... | Queatrix | General Discussions | 21 | 05-21-2007 04:48 PM |
| FAQ Check/Lock | RoD | A Brief History of Cprogramming.com | 2 | 10-15-2002 11:21 AM |