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


Please Help Members By Posting Answers For Below Questions

Explain the use of 'auto' keyword in c programming?

666


What are the application of void data type in c?

680


What are the storage classes in C?

614


Why is c still so popular?

602


Should I learn data structures in c or python?

567






Why #include is used in c language?

584


Can a pointer be null?

550


#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

772


What is a global variable in c?

581


How can a number be converted to a string?

586


Why does notstrcat(string, "!");Work?

630


Explain what is wrong with this program statement?

608


What is #include conio h?

581


Write a program in c to replace any vowel in a string with z?

680


Explain how do you declare an array that will hold more than 64kb of data?

878