![]() we need to allocate memory to these data structures explicitly. ![]() ![]() However, when we go to complex programming taking into account the basic data structures like trees, queues, and lists, etc. We have almost covered every section a C code may have then what is the purpose of the heap here? Whenever we write a program, we never allocate memory explicitly for simple variables. The last memory segment in memory allocation of code is a heap. These variables were stored into the stack as long as the LC is inside the function, at the time it exits from the function, the compiler pops all the local variables from the stack and move the LC to the return address pushed onto the stack. At the time of function call, the location counter pushes the return address of the main code (the line next to the function call) onto the stack, after that LC (location counter) moves to the function and push all the local variables of the function (initialized and uninitialized) onto the stack. ![]() This data of a function is stored in the Stack. We don’t have that large of a memory to accommodate separate section for each of a function in a thousand-line code. The question here is, how does the location counter know where to return after the completion of the code, and where to store the variables we initialize inside the function? Stack Framesĭoes every function create a separate memory segment for storing its data? After the execution of the function (function call completion) the location counter return to the main code where it left the main code at the time of function call initialization. Whenever we want to call a function, the location counter jumps to the function and leave the main code to execute the code inside the function. Out of all the memory blocks, this memory block is the one having quite critical functionality. stack and heap, we will first have a brief discussion of the purpose and usage of each of them after that we will compare their cause. Now comes the major topic of discussion i.e. Any uninitialized data either global, static or normal variable are placed in this section. During the execution of the code all the variables present in this section are initialized to 0 automatically. This segment in memory is also sometimes referred as bss “block started by symbol” segment. the variables that were not initialized by the programmer explicitly. Same again as the name suggests, this portion of memory contains uninitialized data set, i.e. Note that this data segment is not read-only because the value of initialized data can be altered at run time. It is basically a virtual address space of the program and it not only contains variables which are initialized by the programmer but also the global and static variables as these were also in the initialized state. Initialized data segmentĪs the name suggests, initialized data segment contains data segments or data elements which were initialized by the user. Usually it is placed below the heap or stack in memory so that any overflow in any of them do not results in the overwriting of code section (which is not acceptable in any case). Text segment is also known as code segment or simple text because it contains the complete executable code and the compiler will go through this section line by line for execution. In memory allocation this segment plays an important role as it saves the whole code in it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |