answersLogoWhite

0


Best Answer

Static memory allocation is memory allocated on the "stack" and cannot be resized after the initial allocation, while dynamic memory allocation is memory allocated in the "heap", and can be dynamically expanded and shrunk as necessary.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

9y ago

Static variables are named variables allocated within the program's data segment along with named constants and named global variables. Dynamic variables are unnamed (anonymous) variables allocated on the heap. In order to access an unnamed variables, you must also maintain a named variable (a pointer) either in the data segment or on the stack. The stack is typically used to store named local variables, return values, pass by value semantics and exception handling. Groups of unnamed variables (aggregates) can be stored in structures such as arrays or lists which can be accessed through a single reference to the start of the structure.

This answer is:
User Avatar

User Avatar

Wiki User

8y ago

Static memory is allocated at compile time. Dynamic memory is allocated at runtime.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Difference between dynamic and static memory allocation?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are types of memory allocation?

There are two types of memory allocations. 1. Static memory allocation 2. Dynamic memory allocation


What is the use of Constructor with Dynamic allocation?

Constructors are necessary to initialize classes. It allows to avoid to a lot of problems with unauthorized access of memory. Dynamic allocation makes possible allocation of memory during execution of program. If you do not use dynamic allocation, all required memory will be allocated during initialization phase (constructors are usually responsible for that). But you can't use more memory. Dynamic allocation was designed to overcome such problems.


What Linked list uses.type of memory allocation?

Linked lists use dynamic memory allocation (also called "heap memory allocation", as the linked list is stored in heap memory).


What are the problem associated with dynamic memory allocation?

Not freeing it when you no longer need the memory.


Advantages of dynamic memory allocation in data structure?

The main advantage of dynamic memory allocation is flexibility: the sizes of structures (or upper bounds on the sizes) do not need to be known in advance, so any size input that does not exceed available memory is easily handled. There are costs, however. Repeated calls to allocate and de-allocate memory place considerable strain on the operating system and can result in "thrashing" and decreased performance. In addition, one has to be very careful to "clean up" and de-allocate any memory that is allocated dynamically, to avoid memory leaks. The general rule of thumb is, if you can allocate memory statically, do it, because the result will probably be faster code that is easier to debug. But if you need to handle wide-ranging input sizes, then dynamic memory allocation is the way to do it.

Related questions

What are types of memory allocation?

There are two types of memory allocations. 1. Static memory allocation 2. Dynamic memory allocation


What is difference in static and dynamic storage allocation?

Static storage allocation is when a program dedicates an amount of memory for its use at the start of the program. Dynamic storage allocation is when a program only takes storage as it needs it.


Compare and contrast dynamic memory allocation and the allocation of files in secondary storage?

Static Memory Allocation: Allocating the total memory requirements that a data structure might need all at once without regard for the actual amount needed at execution time. Dynamic Memory Allocation: The opposite strategy of static memory allocation - Dynamic Memory Allocation, involves allocating memory as-needed.


How do you display matrix in c using dynamic memory allocation?

Memory allocation is not necessary to display a matrix.


What is the use of Constructor with Dynamic allocation?

Constructors are necessary to initialize classes. It allows to avoid to a lot of problems with unauthorized access of memory. Dynamic allocation makes possible allocation of memory during execution of program. If you do not use dynamic allocation, all required memory will be allocated during initialization phase (constructors are usually responsible for that). But you can't use more memory. Dynamic allocation was designed to overcome such problems.


What Linked list uses.type of memory allocation?

Linked lists use dynamic memory allocation (also called "heap memory allocation", as the linked list is stored in heap memory).


What are the problem associated with dynamic memory allocation?

Not freeing it when you no longer need the memory.


What is the special features of pointers in c?

Dynamic memory allocation


Difference between contiguous and non contiguous memory allocation?

In a contiguous memory allocation there is no overhead during execution of a program. In a non contiguous memory allocation address translation is performed during execution.


At what time the memory is allocated for variable in c and c?

Static memory allocation occurs at compile time where as dynamic memory allocation occurs at run time.


What are the different function used for dynamic memory allocation?

alloc :- to allocate memory. calloc :- to free the memory.


What are the recent memory management schemes?

Single-user contiguous Fixed Partitions Dynamic Partitions Relocatable Dynamic Partitions Paged Memory Allocation Demand Paging Working Set Segmented Memory Allocation Segmented/Demand Page Memory Allocation -------Taken from "Understanding Operating Systems. 6th edition pg 99