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
Why does this code crash?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
What is oops c?
Give differences between - new and malloc() , delete and free() ?
I completed my B.tech (IT). Actually I want to develop virtual object that which will change software technology in the future. To develop virtual object what course I have to take. can I any professor to help me.
What are the parts of c program?
What is null in c?
What are the types of data files?
7-Given an index k, return the kth row of the Pascal's triangle. For example, when k = 3, the row is [1,3,3,1]. For reference look at the following standard pascal’s triangle.
1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.
How variables are declared in c?
What are the back slash character constants or escape sequence charactersavailable in c?
What is the difference between call by value and call by reference in c?
What is the use of sizeof?
Why can't I perform arithmetic on a void* pointer?