stack and heap

15

Upload: baabtracom-no-1-supplier-of-quality-freshers

Post on 06-Jul-2015

610 views

Category:

Education


0 download

DESCRIPTION

Stack and heap

TRANSCRIPT

Page 1: Stack and heap
Page 2: Stack and heap

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

Page 3: Stack and heap

Week Target Achieved

1 25 17

Typing Speed

Page 4: Stack and heap

STACK & HEAP

Swafeena Nima KM

Swafeenanima @gmail.com

www.facebook.com/

Swafeenanima

twitter.com/username

in.linkedin.com/in/

Swafeenanima

9562852057

Page 5: Stack and heap

STACK

The stack is a common data structure for representing things

Need to maintained in a particular order

LIFO

Page 6: Stack and heap

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

Page 7: Stack and heap

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

Page 8: Stack and heap

STACK (contd..)

Example For Stack overflow

#include <stdio.h>

int main()

{

int nStack[100000000];

return 0;

}

Page 9: Stack and heap

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

Page 10: Stack and heap

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

Page 11: Stack and heap

STACK AND HEAP EXAMPLES

public void Method1()

{

int i=4;

int y=2;

class1 cls1 = new class1();

}

Page 12: Stack and heap

STACK AND HEAP EXAMPLES (contd..)

Page 13: Stack and heap
Page 14: Stack and heap

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

Page 15: Stack and heap

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]