Stack and heap

0 views
657 views

Published on

Stack and heap

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
0
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Stack and heap

  1. 1. 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
  2. 2. Typing Speed Week Target Achieved 1 25 17
  3. 3. STACK & HEAP Swafeena Nima KM Swafeenanima @gmail.com www.facebook.com/ Swafeenanima twitter.com/username in.linkedin.com/in/ Swafeenanima 9562852057
  4. 4. STACK  The stack is a common data structure for representing things  Need to maintained in a particular order LIFO
  5. 5. 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
  6. 6. 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
  7. 7. STACK (contd..) Example For Stack overflow #include <stdio.h> int main() { int nStack[100000000]; return 0; }
  8. 8. 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
  9. 9. 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
  10. 10. STACK AND HEAP EXAMPLES public void Method1() { int i=4; int y=2; class1 cls1 = new class1(); }
  11. 11. STACK AND HEAP EXAMPLES (contd..)
  12. 12. 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
  13. 13. 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

×