2. Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
4. STACK & HEAP
Swafeena Nima KM
Swafeenanima @gmail.com
www.facebook.com/
Swafeenanima
twitter.com/username
in.linkedin.com/in/
Swafeenanima
9562852057
5. STACK
The stack is a common data structure for representing things
Need to maintained in a particular order
LIFO
6. STACK (contd..)
Local variables are stored on the stack
Stores temporary variables created by each function
Often a function or method calls another function which in turn
calls another function etc
7. STACK (contd..)
The stack has a fixed size
Both stack and heap are store on the RAM
If there is not enough space on the stack to handle the
memory being assigned to it, a stack overflow occurs
8. STACK (contd..)
Example For Stack overflow
#include <stdio.h>
int main()
{
int nStack[100000000];
return 0;
}
9. HEAP
The heap is simply the memory used by programs to store
global variables
Heap variables have no dependencies with each other and
can always be accessed randomly at any time
Used for dynamic memory allocation
10. HEAP (contd..)
It is a more free-floating region of memory (and is larger)
To allocate memory malloc() , calloc() or realloc()
To deallocate memory free() [Memory leak]
Does not have size restrictions on variable size
Heap memory is slightly slower to be read from and written to
11. STACK AND HEAP EXAMPLES
public void Method1()
{
int i=4;
int y=2;
class1 cls1 = new class1();
}
14. If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
15. Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550