How does memory allocation is occurred during executing a simple C program .??

Asked by Last Modified  

Follow 0
Answer

Please enter your answer

Advanced computer Software and Design as per industry standard

Segment Description Code - text segment Often referred to as the text segment, this is the area in which the executable or binary image instructions reside. For example, Linux/Unix arranges things so that multiple running instances of the same program share their code if possible. Only one copy...
read more
Segment Description Code - text segment Often referred to as the text segment, this is the area in which the executable or binary image instructions reside. For example, Linux/Unix arranges things so that multiple running instances of the same program share their code if possible. Only one copy of the instructions for the same program resides in memory at any time. The portion of the executable file containing the text segment is the text section. Initialized data – data segment Statically allocated and global data that are initialized with nonzero values live in the data segment. Each process running the same program has its own data segment. The portion of the executable file containing the data segment is the data section. Uninitialized data – bss segment BSS stands for ‘Block Started by Symbol’. Global and statically allocated data that initialized to zero by default are kept in what is called the BSS area of the process. Each process running the same program has its own BSS area. When running, the BSS, data are placed in the data segment. In the executable file, they are stored in the BSS section. For Linux/Unix the format of an executable, only variables that are initialized to a nonzero value occupy space in the executable’s disk file. Heap The heap is where dynamic memory (obtained by malloc(), calloc(), realloc() and new – C++) comes from. Everything on a heap is anonymous, thus you can only access parts of it through a pointer. As memory is allocated on the heap, the process’s address space grows. Although it is possible to give memory back to the system and shrink a process’s address space, this is almost never done because it will be allocated to other process again. Freed memory (free() and delete – C++) goes back to the heap, creating what is called holes. It is typical for the heap to grow upward. This means that successive items that are added to the heap are added at addresses that are numerically greater than previous items. It is also typical for the heap to start immediately after the BSS area of the data segment. The end of the heap is marked by a pointer known as the break. You cannot reference past the break. You can, however, move the break pointer (via brk() and sbrk() system calls) to a new position to increase the amount of heap memory available. Stack The stack segment is where local (automatic) variables are allocated. In C program, local variables are all variables declared inside the opening left curly brace of a function's body including the main() or other left curly brace that aren’t defined as static. The data is popped up or pushed into the stack following the Last In First Out (LIFO) rule. The stack holds local variables, temporary information, function parameters, return address and the like. When a function is called, a stack frame (or a procedure activation record) is created and PUSHed onto the top of the stack. This stack frame contains information such as the address from which the function was called and where to jump back to when the function is finished (return address), parameters, local variables, and any other information needed by the invoked function. The order of the information may vary by system and compiler. When a function returns, the stack frame is POPped from the stack. Typically the stack grows downward, meaning that items deeper in the call chain are at numerically lower addresses and toward the heap. read less
Comments

B.E+MBA

You need to study stacks and LIFO principle
Comments

Lecturer Computer Applications

C language supports two kinds of memory allocation: 1 static allocation 2. dynamic allocation. static allocation is of a fixed size. It is allocated only once, when your program is started and never freed till program is running or the variable is in scope. In dynamic allocation size of required memory...
read more
C language supports two kinds of memory allocation: 1 static allocation 2. dynamic allocation. static allocation is of a fixed size. It is allocated only once, when your program is started and never freed till program is running or the variable is in scope. In dynamic allocation size of required memory depends on factors that are not known before the program runs. There are functions which we cal call to allocate memory at run-time. Example: malloc(), realloc(). Further, memory representation is of below sections: 1. Text segment 2. Initialized data segment 3. Uninitialized data segment 4. Stack 5. Heap read less
Comments

Expert in Computer Science

Dynamic memory allocation is used to manage available memory, as memory allocation decisions are taken at run time
Comments

Math Mad

Memory allocation is of types: Static Memory Allocation and Dynamic Memory allocation. Static is a fixed one and is allocated once during compile time, whereas dynamic memory is allocated during run time.
Comments

C, C++, Embedded Systems Trainer

The storage class determines the part of memory where storage is allocated for an object (particularly variables and functions) and how long the storage allocation continues to exist. A scope specifies the part of the program which a variable name is visible, that is the accessibility of the variable...
read more
The storage class determines the part of memory where storage is allocated for an object (particularly variables and functions) and how long the storage allocation continues to exist. A scope specifies the part of the program which a variable name is visible, that is the accessibility of the variable by its name. In C program, there are four storage classes: automatic, register, external, and static. Keep in mind that in the hardware terms we have primary storage such as registers, cache, memory (Random Access Memory) and secondary storage such as magnetic and optical disk. read less
Comments

There are 2 types of memory allocation in c: 1. Dynamic memory allocation-Runtime 2 Compile time -static In dynamic memory allocaion your variables size will be decided on runtime. In static memory allocation variables size are fixed, so its size is decided on compile time.
Comments

Software Professional Trainer with 26+ years of Experience in Software Design and Development

Static memory will get allocated during compile time. Dynamic memory allocation will happen during program run time Memory segments are segregated as mentioned below. Text segment - All the source code will be stored Data Segment - Initialized data segment - Static and Global...
read more
Static memory will get allocated during compile time. Dynamic memory allocation will happen during program run time Memory segments are segregated as mentioned below. Text segment - All the source code will be stored Data Segment - Initialized data segment - Static and Global variable which are initialised Uninitialized data segment (BSS) - Static and Global variable which are uninitialised Stack - Static memory allocation for auto variable Heap - Dynamic memory allocation for pointer read less
Comments

Computer Software Training Classes

cache memory
Comments

Trainer

1. Dynamic memory allocation-Runtime 2 Compile time -static
Comments

View 8 more Answers

Related Questions

What are codes required to create a new operating system?
^^ He is asking about Operating System not windows and for creating Operating System you should have a good knowledge of various complex areas of computer science from hardware to software like OS algorithms,...
Vijay
I want to learn swift programming language ,pl advise
If you are a fresher and wants to get into iOS apps developement , you must know OOPs and Objective-C .. Suppose if you get into any Company and they give old application which was written in Objective-C...
Satyaraju
0 0
7
If the class has access modifier with protected then the constructor of that class is public or protected?
Variables, methods and constructors which are declared protected in a superclass can be accessed only by the subclasses in other package or any class within the package of the protected members' class. The...
Sudheer
Are there any free online certification courses available or not?
Actually your question is wrong, first decide which certification you need, Then get some working experience, prepare for certification. For the free certification, i never seen any authenticated certification...
Chaganti
What is the difference between Paste and Paste Special Option in Excel?
Paste is a feature that lets users cut or copy items from a Cells and transfer them to another. Paste Special allows the items being transferred to be formatted in several different ways. Paste Special...
Vijaya lakshmi

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

Efficient Learning Strategies
Type your notes after class Write your notes onto flashcards - Scrabble -Make posters Review flashcards while walking, at gym, etc. Dog-ear pages in the reading where you can find...

Student Project Development: How To Go About It?
A lot of students (count me as well) in their final year of IT course are confused and overwhelmed about their Project development. Final Year IT Projects are a crucial milestone in every IT students educational...

Merge Multiple PST Files into One Using PST Merge Tool
Overview of PST Merge Software The PST Merge is a software which merge multiple PST files into a single PST file. It makes sure that when PST files are merged into a new file, the original PST files should...

Essential SQL Tips For Developers And For MS SQL DBA
10 Essential SQL Tips for Developers: SQL is yet another essential language for developers wishing to create data-driven websites. However, many developers are unfamiliar with various aspects of SQL;...

10 Study Tips to Achieve your Goals
This is particularly true of students that are looking to make the most of their study time and get better grades at Organization. 1. Set Study Goals: There is lots of credible research suggesting that...

Recommended Articles

Decades back, when computers were being introduced in office premises, PPT was a new terminology that all employees tried to learn. Now PPT has made its way far away from offices and is an integral part of schools, colleges, and several other official proceedings. This is because PPT is an user-friendly computerized method...

Read full article >

Whether you are using a laptop or a desktop, the mouse surely takes up time. Imagine if you could alone manage with the keys and not have to move your hands around the mouse? That would have been faster and so much time-saving. For example, Control + Z for undo or Control + Y for redo, definitely saves time when we are...

Read full article >

Software Development has been one of the most popular career trends since years. The reason behind this is the fact that software are being used almost everywhere today.  In all of our lives, from the morning’s alarm clock to the coffee maker, car, mobile phone, computer, ATM and in almost everything we use in our daily...

Read full article >

MCTS Certification in India The Microsoft Certified Technology Specialist or MCTS certification is suited for professionals who want to get into profession of implementing, building, troubleshooting, and debugging a particular Microsoft technology. The MCTS certification can give you a clear edge over others to showcase...

Read full article >

Looking for Computer Software Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you