0% found this document useful (0 votes)
64 views

Static

Uploaded by

SATYA TECH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Static

Uploaded by

SATYA TECH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Difference Between Static and

Dynamic Memory Allocation


Memory allocation is an important concept in programming. Essentially, it is the process
of allocating memory space to a certain computer program. Memory allocations are
divided into two categories. The difference between static and dynamic memory
allocation is an important topic in the GATE CSE syllabus.

Key Difference Between Static and Dynamic Memory Allocation


Static Memory Allocation Dynamic Memory Allocation

Static memory refers to memory allocation Dynamic memory allocation refers to memory
that occurs during the compilation allocation that occurs during the execution or
process. runtime of a program.

It makes use of a stack to manage It makes use of a heap to manage dynamic


memory allocation that is static. memory allocation.

It is less efficient. It is more efficient.

Once the memory has been allocated, it


Memory can be allocated at any point throughout
will be available throughout the
the application.
application.

It is faster than dynamic memory


It is slower than static memory allocation.
allocation.

The memory in a static memory allocation During the execution of a program, dynamic
cannot be altered while the application is memory allocation allows the memory to be
running. altered.

Static and Dynamic Memory Allocation


Memory allocation takes place either before or during program execution. Memory
allocations are divided into two categories:

1. Static Memory Allocation or Compile-time Memory Allocation


2. Memory Allocation at Runtime or Dynamic Memory Allocation

What is Static Memory Allocation?


When you use Static Memory Allocation, the memory for your data is allocated at the
start of the application. When the program is created, the size is set. It applies to
variables in the global scope, variables in the file scope, and variables qualified by
statically defined inside functions. This memory allocation is set in stone and cannot be
altered, i.e. increased or lowered once it has been allocated. As a result, precise
memory needs must be understood ahead of time.

• Memory is allocated during the compilation process.


• It makes use of a stack to keep track of the memory allocation.
• The memory size of this allocation cannot be changed once it has been allocated.
• It is ineffective.

Static memory allocation occurs when the ultimate size of a variable is chosen before
the program is performed. Compile-time memory allocation is another name for it.

What is Dynamic Memory Allocation?


The technique of assigning memory space during execution or run time is known as
dynamic memory allocation. During the execution of the program, it generates overhead
for each operation over the system, slowing down the overall process. It allows for more
flexibility in terms of allocation by performing operations on different areas of the
program, which reduces waste. The advantages of allocating memory dynamically are
mentioned below.

• When we don't know how much memory will be required for the software ahead of time.
• When we need data structures that don't have a memory restriction.
• When you wish to make better use of your memory space.
• Dynamic memory allocation is required when using the concepts of structures and linked
lists in programming.

Similarities Between Static and Dynamic Memory


Allocation
The following are the similarities between the two types of allocation memory:

• They're both memory management systems.


• Both can be done manually with the assistance of a coder.

You might also like