Computer Memory: Key Concepts and Importance
Explore the fundamentals of computer memory, its significance in computing, and the different types of memory allocation and management. Learn about the role of memory in program execution and the distinction between user space and kernel space. Dive into the principles of stack and heap memory, and their respective functions in program execution. Gain insights into the evolving landscape of memory management over time, from the early days of C programming to modern languages. Discover the crucial role of memory in solving complex computational problems and the essential considerations when writing efficient computer programs.
Download Presentation

Please find below an Image/Link to download the presentation.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.
You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.
The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.
E N D
Presentation Transcript
Memory in Computer Yung-Hsiang Lu Purdue University 1
C vs. Newer Languages When C was developed (late 1960s to early 1970s), computers were slow. Thus, C's design principle is "A C program does exactly what it is instructed to, nothing more." C does not initialize variables, i.e., uninitialized variables contain uncertain values. C does not release memory, i.e., no garbage collection like Java. C does not check errors. Programmers are responsible for correctness. 2
Why Do Computers Need Memory? Imagine that you are solving a complex problem. You need some reference books (also called "read-only memory") and some scratch paper. "Memory" in computers is the reference books and scratch paper Computers were very expensive and memory was precious. Thus, memory management is an important topic when writing computer programs 3
This core memory is about the size of your mobile phone. Your phone can store about 10,000,000 times more data. 4
Memory in Computers User Space Kernel Space (can be used by ordinary programs) (only operating system can use) 5
User Space Memory Stack Memory Heap Memory Program Memory 6
User Space Memory Follow "first-in last- out" rule Stack Memory Can be allocated and released by programs Heap Memory Program Memory Store programs 7
Stack Memory is a type of memory inside computers strictly follows the "first-in last-out" (or last-in first-out) rule is indirectly controlled by your programs is directly controlled by compilers and operating systems 8
What is stack? "Stack" means what comes first leaves last. You are using this concept everyday. You put on socks before putting on shoes. You take off the shoes before taking off the socks. You put on a shirt before wearing a jacket. You take off the jacket before taking off the shirt. When you put a book on the top of a pile, the last added book is removed first. 9
Stack Memory in Programs Consider this snippet of code: f1 calls f2 and f2 calls f3 f1() { f2(); } f1 is seen first, then f2, then f3 f2() { f3(); } When f3 finishes, the program continues from f2, not f1 10
Stack Memory in Programs The stack memory has only one function, i.e., f1 f1() { If the program is here f2(); } f2() { f3(); f1 } 11
Stack Memory in Programs Conventionally, the stack memory starts from bottom and grows upwards. f1() { f2(); The stack memory has two functions now, i.e., f1 and f2 } f2() { If the program is here f2 f1 f3(); } 12
Stack Memory in Programs After f3 finishes, the program continues f2. f1() { f2(); } f2() { f2 f1 f3(); If the program continues here } 13
Stack Memory in Programs After f2 finishes, the program continues f1. f1() { f2(); If the program continues here } f2() { f1 f3(); } 14
That's the idea. The next lecture will be more precise and get into the details 15