C# 递归深度 - 你能走多远 [英] C# Recursion Depth - How Deep can you go

查看:57
本文介绍了C# 递归深度 - 你能走多远的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以控制递归调用的次数?

从一个基本的测试程序中,我得到了超过 18k 的递归深度

这取决于堆栈大小....

有没有办法设置一块内存(可能是一个线程)和一个巨大的堆栈来增加递归深度?

解决方案

我在某些文档识别过程中增加了堆栈大小.真的很需要.

因此您可以使用以下代码增加线程的堆栈大小:

var stackSize = 10000000;线程线程 = new Thread(new ThreadStart(BigRecursion), stackSize);

<块引用>

Thread(ThreadStart, Int32) --初始化一个新的实例线程类,指定最大值线程的堆栈大小.

来源

希望这是你需要的.

Is there any control how much you can Recursively call something?

From a basic test program I get a recursion depth of just over 18k

which depends on the stacksize....

is there a way to set up a chunk of memory (perhaps a thread) with a massive stack to increase recursion depth?

解决方案

I've increased the stack size during some documents recognition. It was really needed.

So you can increase stack size for thread using following code:

var stackSize = 10000000;
Thread thread = new Thread(new ThreadStart(BigRecursion), stackSize);

Thread(ThreadStart, Int32) -- Initializes a new instance of the Thread class, specifying the maximum stack size for the thread.

Source

Hope this what you need.

这篇关于C# 递归深度 - 你能走多远的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆