Skip to playerSkip to main content
  • 4 months ago
Sigma batch 2025
Transcript
00:00Next, we will talk about what things are inside the memory.
00:04We write a function and call it a function.
00:08In memory, we will get a lot of special things.
00:12We have done public, static, void.
00:16If I have made a function, let's calculate sum.
00:20I will have a variable like int a, a other variable like int b.
00:24These are my formal parameters.
00:26In this sum, I have made a new variable.
00:30Int sum is equal to a plus b.
00:32Then, I will print it as well.
00:34Besides, I have made a public, static, void.
00:36Main name function.
00:38In my class.
00:40In which I know I am taking a string of arguments.
00:44I have called sum.
00:46What is inside my memory?
00:50Today, we have been able to imagine the time of the memory.
00:54My memory is something like that.
00:56Each variable is a little place.
00:58It is a name of the variable.
01:00It is a value store.
01:02We knew that there is a value store.
01:04We knew that there is a value store.
01:06The variables occupy their memory.
01:08But the functions also occupy the memory in Java.
01:12For writing functions, there is a little memory.
01:16They have some memory.
01:18Where do they have memory?
01:20They have called stack.
01:22Stack which students have heard the first time term.
01:24Stack means to keep things on top of one.
01:28Like plates in restaurants.
01:30We keep them on top of one.
01:32We keep books on top of the table.
01:34They keep on top of one.
01:36We call stack of books.
01:38Or stack of plates.
01:40Stack is to keep things on top of one.
01:44So, in Java, there is some parts that are organized in the stack.
01:48So, it shows something like this.
01:50First, there is some parts.
01:52Then, there is some parts.
01:54Then, there is some parts.
01:55Then, there is some parts.
01:56So, this way, they keep things on top of one.
01:58So, this part of memory,
02:00we call it call stack.
02:02We call it call stack.
02:04Call stack tracks.
02:05Call stack tracks.
02:06Which function has called.
02:07Which function has called.
02:08Which function has called.
02:09Or, which function is called in our memory.
02:10Now, we call it in our memory.
02:11Or, we occupy some memory.
02:12So, like a Java program is running.
02:14Like this program is running.
02:15So, what will happen first?
02:16First of all, the main function will occupy some memory.
02:21And, the amount of memory will occupy this stack.
02:24This is my call stack.
02:26I will call it a stack frame.
02:30Frame is a hole.
02:33So, the memory has occupied the main function.
02:37Now, what is stored in this memory?
02:39What is stored in this memory?
02:40In this memory, all the variables are stored.
02:42So, if I have made a sum.
02:46Then, what will happen?
02:48The main function stack frame will store the string type.
02:52And, as the main function has called the sum.
02:55So, the sum has called the call.
02:57So, the stack frame has occupied the sum function.
03:01So, the sum function will occupy this stack frame.
03:04And, what will be stored in this sum function?
03:07Because, the sum function of the integer variable is called sum.
03:11So, the integer variable will occupy this stack frame.
03:17If this sum calls some other function.
03:20So, what will happen?
03:21It will become another stack frame.
03:23In which it will be named a new function.
03:25And, its variables are stored here.
03:27So, a function occupies on the stack frame.
03:32And, what is stored in it?
03:34It is stored in the function related information.
03:37So, the input will be stored in it.
03:39It will be stored in it.
03:40The variables will be stored in it.
03:41The variables will be stored in it.
03:43So, this is why the function also needs memory.
03:45It also needs memory.
03:46And, it takes memory in the form of the call stack.
03:48Now, the whole concept of the call stack.
03:50We will be reading it again.
03:52It will be basic in the name of the recursion.
03:55So, if it is a little difficult to understand.
03:58Then, we will study Oops.
04:00We will discuss the functions in detail.
04:02We will discuss the class in detail.
04:04Then, we will study recursion.
04:05So, when we are reading recursion,
04:07We will discuss the call stack in detail.
04:09And, all of the things will be clear.
04:11So, why is it important to understand the memory?
04:15Because, in the name of the recursion,
04:17There is a wonderful technique in programming languages.
04:20There are many algorithms that use it.
04:23So, that is why,
04:24It is important to understand the call stack.
04:26Because, the call stack forms the basis of recursion.
04:29So, the function is called.
04:30So, the memory is reserved for that function.
04:33And, as we have a return statement of function.
04:36If we have a return statement here.
04:37So, as I will execute the return statement.
04:38And, in the name of the function,
04:39If I have a return statement here.
04:40So, after I execute this statement,
04:43I will reach this return statement.
04:45And, I will go into the main function.
04:49So, what the function of the call stack has occupied memory,
04:51will be removed.
04:52And, as the main function will be removed.
04:56So, the main function will be removed.
04:59So, when the function is called,
05:01It will occupy memory or place.
05:03And, when it is done,
05:05If the return statement is executed then it will be removed from the call stack.
Be the first to comment
Add your comment

Recommended