Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19

Warning: Function ereg() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 4

Warning: Function split() is deprecated in ..../includes/class_postbit.php(345) : eval()'d code on line 19
2 questions with recursion - Page 2
Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: 2 questions with recursion

  1. #11

    Re: 2 questions with recursion


    Fear not. The antive-code compiler of O'Caml has no stack limit. You can infinitely call a function without problems.
    Do fear. Each time you call a function, it has to save the return address to the stack. (That's how the x86 processor works, not the programming language itself.) Additionally, in C, a function is not required to preserve the eax, ecx, or edx registers, so those must be pushed before the call is made. And to lump onto that, since the ebx, esi, and edi registers aren't preserved, they must be pushed at the beginning of a function. (That is unless you don't use them, but only in assembler can you make that distinction.) And while C is different from O'Caml, all the registers must be preserved in practically any language. And to add onto it even more, in many languages, arguments are passed through the stack. So if you were calling a function with a single integer argument, that's likely 8 32-bit things added to the stack right there, for a total of 32 bytes. Add onto that that it has to have memory for local variables for each of those functions. It's not much by itself, but when you have about 10,000 recursions or more, that starts to consume a good amount of memory, not to mention all the processor overhead it takes to work the stack. So to put it basically, don't abuse recursion.

  2. #12
    Guest

    Re: 2 questions with recursion

    When it can O'Caml will convert a recursive function to an iterative one. In the case of an infinite recursion, it is roughly translated to:
    Code:
    while true do
     <code>
    end
    You gotta remember: O'Caml's compiler are intelligent.

Similar Threads

  1. Soft lockup/ spin lock recursion problem in 2.6.17.13
    By gopala.surya in forum Redhat / Fedora
    Replies: 4
    Last Post: 10-18-2006, 12:43 AM
  2. Bash :: Command recursion to a directories' contents
    By Schotty in forum Linux - Software, Applications & Programming
    Replies: 7
    Last Post: 01-27-2003, 07:31 PM
  3. Questions...
    By iansl in forum Mandriva
    Replies: 37
    Last Post: 06-19-2002, 11:00 PM
  4. some questions on 2 hd's
    By in forum Linux - Hardware, Networking & Security
    Replies: 12
    Last Post: 01-25-2002, 09:14 AM
  5. AGP questions
    By thor4linux in forum Linux - General Topics
    Replies: 4
    Last Post: 01-02-2002, 06:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •