The concept of dynamic memory and compares it to static memory. Dynamic memory allows data structures to change size during program execution, providing more flexibility but also requiring careful management. Examples of dynamic memory use include printer queues and airliners. The document also provides a view of memory, including the code, global variables, stack (a static area), and heap (a dynamic area).
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.