SlideShare una empresa de Scribd logo
1 de 19
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
Stack and Heap


        Jithin Mathew
        jitmat@gmail.com
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 no more there.
• Any data on the stack for a function will
  automatically be deleted.
• Stacks in computing architectures are regions
  of memory where data is added or removed in
  a last-in-first-out manner.
• 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.
• Example For Stack overflow
        #include <stdio.h>
        int main()
        {
         int nStack[100000000];
        return 0;
        }

• This program that causes a stack overflow.
• If you run this the program will crash
• This program tries to allocate a huge array on
  the stack.
• Because the stack is not large enough to
  handle this array, the array allocation
  overflows into portions of memory the
  program is not allowed to use.
• Consequently, the program crashes.
Heap
• On the other hand, heap is an area of memory
  used for dynamic memory allocation.
• A place for allocating memory that is not part of
  last-in, first-out discipline.
• This used to store global variables.
• Variables on the heap must be destroyed
  manually.
• 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.
Which is more fast?
• The stack is much faster than the heap.
• This is because of the way that memory is
  allocated on the stack.
Stack and Heap Examples
public void Method1()
{
  int i=4;
  int y=2;
  class1 cls1 = new class1();
}
• A class is just a template which contains the
  various attributes and functions.
• Objects are the building blocks of OOP and are
  commonly defined as variables or data
  structures that encapsulate behavior in a
  programmed unit.
• When First line is executed, the compiler
  allocates a small amount of memory in the
  stack.
• Then it stacks this memory allocation on top
  of the first memory allocation.
• When third line is executed it creates a pointer
  on the stack and the actual object is stored in
  a different type of memory location
• When it passes the end control, it clears all
  the memory variables which are assigned on
  stack.
• Did this presentation help you??? Do visit our
  page www.facebook.com/baabtra and like
  us

www.baabtra.com
www.massbaab.com
www.baabte.com
Thank you

Más contenido relacionado

Destacado (7)

XML
XMLXML
XML
 
Java exeception handling
Java exeception handlingJava exeception handling
Java exeception handling
 
XML
XMLXML
XML
 
MIS
MISMIS
MIS
 
Flowchart& algorithom
Flowchart& algorithomFlowchart& algorithom
Flowchart& algorithom
 
XML
XMLXML
XML
 
Html tags
Html tagsHtml tags
Html tags
 

Similar a Stack and heap

Internet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IVInternet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IVArti Parab Academics
 
Heap Memory Management.pptx
Heap Memory Management.pptxHeap Memory Management.pptx
Heap Memory Management.pptxViji B
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorWednesday Solutions
 
Storage management
Storage managementStorage management
Storage managementAtul Sharma
 
02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptx02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptxAnhNhatNguyen5
 
#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future Design#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future DesignPivotalOpenSourceHub
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxSKUP1
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxLECO9
 
4 memory management bb
4   memory management bb4   memory management bb
4 memory management bbShahid Riaz
 
memory managment on computer science.ppt
memory managment on computer science.pptmemory managment on computer science.ppt
memory managment on computer science.pptfootydigarse
 

Similar a Stack and heap (20)

Internet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IVInternet of Things, TYBSC IT, Semester 5, Unit IV
Internet of Things, TYBSC IT, Semester 5, Unit IV
 
C dynamic ppt
C dynamic pptC dynamic ppt
C dynamic ppt
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
Stack and Heap
Stack and HeapStack and Heap
Stack and Heap
 
Heap Memory Management.pptx
Heap Memory Management.pptxHeap Memory Management.pptx
Heap Memory Management.pptx
 
Memory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage CollectorMemory Management in Go: Stack, Heap & Garbage Collector
Memory Management in Go: Stack, Heap & Garbage Collector
 
Memory Management
Memory ManagementMemory Management
Memory Management
 
Storage management
Storage managementStorage management
Storage management
 
Ch4 memory management
Ch4 memory managementCh4 memory management
Ch4 memory management
 
02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptx02D-Memory Management in Java.pptx
02D-Memory Management in Java.pptx
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future Design#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future Design
 
Stack n heap
Stack n heapStack n heap
Stack n heap
 
Apache Geode Offheap Storage
Apache Geode Offheap StorageApache Geode Offheap Storage
Apache Geode Offheap Storage
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptx
 
C MEMORY MODEL​.pptx
C MEMORY MODEL​.pptxC MEMORY MODEL​.pptx
C MEMORY MODEL​.pptx
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
Stack&heap
Stack&heapStack&heap
Stack&heap
 
4 memory management bb
4   memory management bb4   memory management bb
4 memory management bb
 
memory managment on computer science.ppt
memory managment on computer science.pptmemory managment on computer science.ppt
memory managment on computer science.ppt
 

Más de baabtra.com - No. 1 supplier of quality freshers

Más de baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 

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
  • 3. Stack and Heap Jithin Mathew jitmat@gmail.com
  • 4. 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 no more there. • Any data on the stack for a function will automatically be deleted.
  • 5. • Stacks in computing architectures are regions of memory where data is added or removed in a last-in-first-out manner.
  • 6. • 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. • Example For Stack overflow #include <stdio.h> int main() { int nStack[100000000]; return 0; } • This program that causes a stack overflow. • If you run this the program will crash
  • 8.
  • 9. • This program tries to allocate a huge array on the stack. • Because the stack is not large enough to handle this array, the array allocation overflows into portions of memory the program is not allowed to use. • Consequently, the program crashes.
  • 10. Heap • On the other hand, heap is an area of memory used for dynamic memory allocation. • A place for allocating memory that is not part of last-in, first-out discipline. • This used to store global variables. • Variables on the heap must be destroyed manually.
  • 11. • 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. Which is more fast? • The stack is much faster than the heap. • This is because of the way that memory is allocated on the stack.
  • 13. Stack and Heap Examples public void Method1() { int i=4; int y=2; class1 cls1 = new class1(); }
  • 14. • A class is just a template which contains the various attributes and functions. • Objects are the building blocks of OOP and are commonly defined as variables or data structures that encapsulate behavior in a programmed unit.
  • 15.
  • 16. • When First line is executed, the compiler allocates a small amount of memory in the stack. • Then it stacks this memory allocation on top of the first memory allocation.
  • 17. • When third line is executed it creates a pointer on the stack and the actual object is stored in a different type of memory location • When it passes the end control, it clears all the memory variables which are assigned on stack.
  • 18. • Did this presentation help you??? Do visit our page www.facebook.com/baabtra and like us www.baabtra.com www.massbaab.com www.baabte.com