What are advantages and disadvantages of recursive
calling ?
Answer Posted / sk_seeker
Why is recursion frowned upon??
User space programs: memory consumption
----------------------------------------
User stack is a dynamic stack i.e. we page fault on the
stack virtual addresses and resolve the fault by allocating
a physical page. Many recursions can lead to a lot of (user
stack) memory being consumed. In a traditional programming
model, when a thread blocks, then all the memory is stuck
with the thread, until the paging daemon kicks it out. So,
effectively, many threads doing recursive calls can consume
a lot of memory and force memory pressure to occur in the
system i.e. system slows down.
Kernel Space program: stack depth
---------------------------------
A kernel stack is fixed in size i.e. 8K or 16K usually. And
this stack does not grow dynamically in most OSes. So,
there is a bound on how much memory can be used for the
kernel stack, unlike user programs. But, this bound on the
stack size is the reason why recursion is discouraged. More
recursive levels can lead to a stack overflow and this will
panic the box. One might say: hey, my recursive depth is
only 10. But, what is unknown is what amount of kernel
stack is already used up && the stack frame consumption
depends on the chip architecture that is being used.
For both of the above reasons, recursion is avoided in
general kernel programming.
| Is This Answer Correct ? | 20 Yes | 12 No |
Post New Answer View All Answers
What is the heap?
How does pointer work in c?
In this assignment you are asked to write a multithreaded program to find the duplicates in an array of 10 million integers. The integers are between -5000,000 to 5000,000 and are generated randomly. Use 10 threads, each thread works on 1000,000 integers. Compare the time needed to accomplish the task with single thread of execution program. Do not include the time to fill the array with integers in the execution time.
What is the difference between variable declaration and variable definition in c?
What are the complete rules for header file searching?
What are register variables in c?
What is unary operator?
What are the usage of pointer in c?
How can I open files mentioned on the command line, and parse option flags?
Write a program to reverse a given number in c?
What are examples of structures?
What is difference between scanf and gets?
Why clrscr is used in c?
If I have a char * variable pointing to the name of a function ..
What math functions are available for integers? For floating point?