Find limit of recursion: Difference between revisions
Content added Content deleted
(add FreeBASIC) |
(Added Wren) |
||
Line 2,778: | Line 2,778: | ||
I've used gdb and the command <tt>print $eax</tt> to know when the segmentation fault occurred. The result was 2094783. |
I've used gdb and the command <tt>print $eax</tt> to know when the segmentation fault occurred. The result was 2094783. |
||
=={{header|Wren}}== |
|||
I cannot find any published information on the maximum amount of memory that can be used by a fiber's stack - and hence the limit of recursion for a given function - but it appears to be 4 GB on a sufficiently large 64-bit system such as my own (32 GB) with no shell limit. |
|||
The final figure produced by the following script was 536,870,500 and multiplying by 8 (the number of bytes of storage required for the parameter 'n') gives 4,294,964,000 which is just 3,296 bytes short of 4 GB. |
|||
In Wren a fiber's stack starts small and is increased as required. It appears that the runtime makes no attempt to check for any limitation internally leaving the script to eventually segfault. |
|||
<lang ecmascript>var f |
|||
f = Fn.new { |n| |
|||
if (n%500 == 0) System.print(n) // print progress after every 500 calls |
|||
System.write("") // required to fix a VM recursion bug |
|||
f.call(n + 1) |
|||
} |
|||
f.call(1)</lang> |
|||
{{out}} |
|||
<pre> |
|||
... |
|||
536870000 |
|||
536870500 |
|||
Segmentation fault (core dumped) |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |