Stack size under Mono

后端 未结 4 423
野性不改
野性不改 2021-01-11 18:37

I have written a tiny recursive bit of F# code to see how many levels of recursion I can fit onto the stack under .NET/Mono. It just prints the recursion depth whenever it i

4条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-11 19:12

    This code gets around the mono limit. It is useful for dfs in competitive programming.

            public static void IncreaseStack(ThreadStart action, int stackSize = 16000000)
            {
                var thread = new Thread(action, stackSize);
    #if __MonoCS__
            const BindingFlags bf = BindingFlags.NonPublic | BindingFlags.Instance;
            var it = typeof(Thread).GetField("internal_thread", bf).GetValue(thread);
            it.GetType().GetField("stack_size", bf).SetValue(it, stackSize);
    #endif
                thread.Start();
                thread.Join();
            }
    

提交回复
热议问题