Fostering Friendships - Enhancing Social Bonds in the Classroom
Stack and heap
1.
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
6. Stack
• The stack is a place in the computer memory
where all the variables that are declared and
initialized before runtime are stored.
• It is a temporary storage memory, if you come
out of the program the memory of the
variable will not be there.
• Any data on the stack for a function will
automatically be deleted.
7. stack
• In stack , data is added or removed in Last-infirst-out manner(LIFO)
8. stack
• The stack has a fixed size
• Both stack and heap are stored on the RAM
• If there is not enough space on the stack to
handle the memory being assigned to it, a
stack overflow occurs.
9. Example-stack overflow
• Example For Stack overflow
#include <stdio.h>
int main()
{
int nStack[100000000];
return 0;
}
• Causes stack overflow
• Program will crash
10. Heap
• Heap is an area of memory used for dynamic
memory allocation.
• The heap is the memory used by program to
store global variables.
• Variables on the heap must be destroyed
manually.
11. Heap
• Any data on the heap will remain there until
it’s manually deleted by the programmer.
• If the current size of the heap is too small to
accommodate new memory, then more
memory can be added to the heap by the
operating system.
12. Heap
• To allocate memory – malloc(),calloc() or
realloc()
• To deallocate memory-free()[memory leak]
• Does not have size restrictions on variable size
• Heap memory is slower than stack
16. 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
17. 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