View
613
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Stack and heap
Citation preview
Disclaimer: This presentation is prepared by trainees ofbaabtra as a part of mentoring program. This is not officialdocument of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .Ltd
Week Target Achieved
1 25 17
Typing Speed
STACK & HEAP
Swafeena Nima KM
Swafeenanima @gmail.com
www.facebook.com/
Swafeenanima
twitter.com/username
in.linkedin.com/in/
Swafeenanima
9562852057
STACK
The stack is a common data structure for representing things
Need to maintained in a particular order
LIFO
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
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
STACK (contd..)
Example For Stack overflow
#include <stdio.h>
int main()
{
int nStack[100000000];
return 0;
}
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
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
STACK AND HEAP EXAMPLES
public void Method1()
{
int i=4;
int y=2;
class1 cls1 = new class1();
}
STACK AND HEAP EXAMPLES (contd..)
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
Contact Us
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Start up VillageEranakulam,Kerala, India.
Email: [email protected]