Memory allocation | SoloLearn: Learn to code for FREE!


Memory allocation

Dynamic vs static memory allocation in cpp


6/2/2019 6:17:33 AM

Muluken Mnyahl

2 Answers

New Answer


Muluken Mnyahl hi, 🍎 Static memory allocation is one in which any variable is directly added in the memory RAM for execution and the variables are maintend stack and allocated in stack. 🍎 now if more then one variable or function are allocated static then that is first push in the stack then LIFO is used to pop the function and variable and execute that function 🍎 static memory allocation is fast as directly allocated or give chance to get it's resources and complete its execution this way their is fast execution in respect with dynamic memory allocation. 🍎 The stack stores parameters for the function and a return address where the program should pick up when the function is finished. It also reserves a space for a return value to be popped by the system on return. The piece of stack used by a subprogram is called a stack frame. 🍎 Because of its limited size, a stack may "overflow" if too many function calls are made without returning.This situation is dangeros This is the static memory allocation.


Muluken Mnyahl 🍎 dynamic memory allocation is an allocation of function and memory at heap, in heap the memory allocated by the new function in C++, Java and in C malloc() function is used to allocate at the heap. 🍎 if any variable or function is allocated on heap then they store as an pile there, so there are so many stored variable and subroutine parameter, so to prevent the overwrite or leakage of any data of function or variable it's good to deallocated the heap variable and function after using that variables or function 🍎 the deallocation is done by free() function or delete(), dealloc() etc function help. If you have any further query ping me I'll loved to answer with some example of heap types as Fibonacci heap, binary heap are the type of heap and max heap and min heap is used to schedule heap memory so I can give information about that if you needed else provided information for your query is more then sufficient to understand Have these 🍎 🍎 🍎 🍎 🍎 🍎