Sunday, October 24, 2010

Stack and Heap Snippet

*Stack allocation
Image myImage;
myImage.SetAllPixels(ClearColor);

*Heap allocation
Image *imagePtr;
imagePtr = new Image();
imagePtr->SetAllPixels(ClearColor);

...

delete imagePtr;

Stack allocation: Constructor and destructor called automatically when the function is entered and exited.
Heap allocation: Constructor and destructor must be called explicitly.

No comments: