• <legend id='AZ36B'><style id='AZ36B'><dir id='AZ36B'><q id='AZ36B'></q></dir></style></legend>

      <small id='AZ36B'></small><noframes id='AZ36B'>

        • <bdo id='AZ36B'></bdo><ul id='AZ36B'></ul>

        <tfoot id='AZ36B'></tfoot>

        <i id='AZ36B'><tr id='AZ36B'><dt id='AZ36B'><q id='AZ36B'><span id='AZ36B'><b id='AZ36B'><form id='AZ36B'><ins id='AZ36B'></ins><ul id='AZ36B'></ul><sub id='AZ36B'></sub></form><legend id='AZ36B'></legend><bdo id='AZ36B'><pre id='AZ36B'><center id='AZ36B'></center></pre></bdo></b><th id='AZ36B'></th></span></q></dt></tr></i><div id='AZ36B'><tfoot id='AZ36B'></tfoot><dl id='AZ36B'><fieldset id='AZ36B'></fieldset></dl></div>

        C++ 是否限制递归深度?

        时间:2023-08-03
        <i id='BZqZ8'><tr id='BZqZ8'><dt id='BZqZ8'><q id='BZqZ8'><span id='BZqZ8'><b id='BZqZ8'><form id='BZqZ8'><ins id='BZqZ8'></ins><ul id='BZqZ8'></ul><sub id='BZqZ8'></sub></form><legend id='BZqZ8'></legend><bdo id='BZqZ8'><pre id='BZqZ8'><center id='BZqZ8'></center></pre></bdo></b><th id='BZqZ8'></th></span></q></dt></tr></i><div id='BZqZ8'><tfoot id='BZqZ8'></tfoot><dl id='BZqZ8'><fieldset id='BZqZ8'></fieldset></dl></div>
        <legend id='BZqZ8'><style id='BZqZ8'><dir id='BZqZ8'><q id='BZqZ8'></q></dir></style></legend>

          • <bdo id='BZqZ8'></bdo><ul id='BZqZ8'></ul>

              • <small id='BZqZ8'></small><noframes id='BZqZ8'>

                  <tbody id='BZqZ8'></tbody>

                  <tfoot id='BZqZ8'></tfoot>
                • 本文介绍了C++ 是否限制递归深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  在 Python 中存在最大递归深度.似乎是因为 Python 被解释而不是编译.C++ 有相同的概念吗?还是只连接内存限制?

                  In Python there is a maximum recursion depth. Seems it is because Python is interpreted rather than compiled. Does C++ have the same concept? Or it is connected only with RAM limit?

                  推荐答案

                  C++ 中的限制是由于堆栈的最大大小.这通常比 RAM 的大小小几个数量级,但仍然相当大.(幸运的是,像字符串内容这样的大东西通常不会保存在堆栈本身中.)

                  The limit in C++ is due to the maximum size of the stack. That's typically less than the size of RAM by quite a few orders of magnitude, but is still pretty large. (Luckily, large things like string contents are typically held not on the stack itself.)

                  堆栈限制通常可在操作系统级别进行调整.(如果您使用的是 Unix,请参阅内置 ulimit shell 的文档.)这台机器 (OSX) 上的默认值为 8 MB.

                  The stack limit is typically tunable at the OS level. (See the docs for the ulimit shell built-in if you're on Unix.) The default on this machine (OSX) is 8 MB.

                  当然,在计算递归深度时,堆栈的大小本身并不完全有帮助.要知道这一点,您必须计算递归函数(也称为堆栈帧)的激活记录(或多个记录)的大小.最简单的方法(我知道)是使用反汇编器(大多数调试器的功能)并在每个函数的开始和结束时读出堆栈指针调整的大小.这是乱七八糟的.(您可以通过其他方式解决这个问题——例如,计算两次调用中指向变量的指针之间的差异——但它们甚至更令人讨厌,尤其是对于可移植代码.从反汇编中读取值更容易 IMO.)

                  Of course, the size of the stack doesn't entirely help by itself when it comes to working out how deep you can recurse. To know that, you have to compute the size of the activation record (or records) of the recursive function (also called a stack frame). The easiest way to do that (that I know of) is to use a disassembler (a feature of most debuggers) and to read out the size of the stack pointer adjustments at the start and end of every function. Which is messy. (You can work it out other ways – for example, computing the difference between pointers to variables in two calls – but they're even nastier, especially for portable code. Reading the values out of the disassembly is easier IMO.)

                  这篇关于C++ 是否限制递归深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 C++ 中递归到 main() 是否合法? 下一篇:C++ 中相互包含的头文件

                  相关文章

                  最新文章

                  <legend id='3nHir'><style id='3nHir'><dir id='3nHir'><q id='3nHir'></q></dir></style></legend>
                  <i id='3nHir'><tr id='3nHir'><dt id='3nHir'><q id='3nHir'><span id='3nHir'><b id='3nHir'><form id='3nHir'><ins id='3nHir'></ins><ul id='3nHir'></ul><sub id='3nHir'></sub></form><legend id='3nHir'></legend><bdo id='3nHir'><pre id='3nHir'><center id='3nHir'></center></pre></bdo></b><th id='3nHir'></th></span></q></dt></tr></i><div id='3nHir'><tfoot id='3nHir'></tfoot><dl id='3nHir'><fieldset id='3nHir'></fieldset></dl></div>

                    • <bdo id='3nHir'></bdo><ul id='3nHir'></ul>

                    <small id='3nHir'></small><noframes id='3nHir'>

                      <tfoot id='3nHir'></tfoot>