Docsity

Understanding Dynamic Memory: Dynamic vs. Static, Slides of Programming for Engineers

Partial preview of the text

Download Understanding Dynamic Memory: Dynamic vs. Static and more Slides Programming for Engineers in PDF only on Docsity!

Dynamic Memory

Dynamic vs. Static

Static (fixed in size)

• Sometimes we create data structures that

are “fixed” and don’t need to grow or

shrink.

Dynamic (change in size)

• Other times, we want the ability to

increase and decrease the size of our data

structures to accommodate changing

needs.

A View of Memory

Global

Stack (Static Area)

(Store stuff here)

Heap (Dynamic Area)

(Store stuff here)

Code

(What you wrote)

A View of Memory

  • (^) Code (Text): The memory is assigned to store the instructions that need to be executed.
  • (^) Global: Variables that are not declared inside the function and they have the whole lifetime of an application. They are accessible any where during the whole lifecycle of application as long as the application is running.
  • (^) Stack: used to store all the information of function calls and all the local variables (size is fixed).
  • (^) Heap : unlike stack, application heap is not fixed. Its size can vary during the lifetime of the application and there is no set rule for allocation or deallocation of the memory.