c# stack size 확인

C# 2022. 2. 24. 09:56

 

 

https://stackoverflow.com/questions/2901185/checking-stack-size-in-c-sharp

 

public static class Extensions
{
    public static void StartAndJoin(this Thread thread, string header)
    {
        thread.Start(header);
        thread.Join();
    }
}

class Program
{
    [DllImport("kernel32.dll")]
    static extern void GetCurrentThreadStackLimits(out uint lowLimit, out uint highLimit);

    static void WriteAllocatedStackSize(object header)
    {
        GetCurrentThreadStackLimits(out var low, out var high);
        Console.WriteLine($"{header,-19}:  {((high - low) / 1024),4} KB");
    }

    static void Main(string[] args)
    {
        WriteAllocatedStackSize("Main    Stack Size");

        new Thread(WriteAllocatedStackSize, 1024 *    0).StartAndJoin("Default Stack Size");
        new Thread(WriteAllocatedStackSize, 1024 *  128).StartAndJoin(" 128 KB Stack Size");
        new Thread(WriteAllocatedStackSize, 1024 *  256).StartAndJoin(" 256 KB Stack Size");
        new Thread(WriteAllocatedStackSize, 1024 *  512).StartAndJoin(" 512 KB Stack Size");
        new Thread(WriteAllocatedStackSize, 1024 * 1024).StartAndJoin("   1 MB Stack Size");
        new Thread(WriteAllocatedStackSize, 1024 * 2048).StartAndJoin("   2 MB Stack Size");
        new Thread(WriteAllocatedStackSize, 1024 * 4096).StartAndJoin("   4 MB Stack Size");
        new Thread(WriteAllocatedStackSize, 1024 * 8192).StartAndJoin("   8 MB Stack Size");
    }
}

 

 

stack size 수정 (dumpbin, exebin)

(이건 c++ 기준으로 보이는데 exe, dll 이 생성되니 사용하는거 같다)

https://christian289.github.io/dotnet/How-to-change-main-thread-stack-size-in-.NET/

 

.net core 3.1 프로그램에서 dumpbin 시 exe, dll 파일에 대해 아래와 같이 나온다.

exe
          180000 size of stack reserve
            1000 size of stack commit
          100000 size of heap reserve
            1000 size of heap commit


dll
          100000 size of stack reserve
            1000 size of stack commit
          100000 size of heap reserve
            1000 size of heap commit

 

하지만 위의 stackoverflow 방식으로 확인하면 아래와 같다.

Main    Stack Size :  1536 KB
Default Stack Size :  1536 KB

'C#' 카테고리의 다른 글

object pool, object type pool  (0) 2022.03.11
GC TEST  (0) 2022.03.08
GC EventPipe 모니터링  (0) 2022.03.08
C# .net core 빌드 및 powershell 전송  (0) 2022.03.01
숫자 범위 추출 및 확장  (0) 2021.11.03
C# LZ4  (0) 2021.10.20
dictionary 에 action 매핑시 instance method 호출 방법  (0) 2021.10.16
[ASP.NET] .net core 2.2 singleton controller  (0) 2019.08.29