Microsoft MVP성태의 닷넷 이야기
.NET Framework: 357. .NET 4.5의 2GB 힙 한계 극복 [링크 복사], [링크+제목 복사],
조회: 32031
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 

(시리즈 글이 6개 있습니다.)
.NET Framework: 188. .NET 64비트 응용 프로그램에서 왜 (2GB) OutOfMemoryException 예외가 발생할까?
; https://www.sysnet.pe.kr/2/0/946

.NET Framework: 266. StringBuilder에서의 OutOfMemoryException 오류 원인 분석
; https://www.sysnet.pe.kr/2/0/1171

.NET Framework: 357. .NET 4.5의 2GB 힙 한계 극복
; https://www.sysnet.pe.kr/2/0/1403

.NET Framework: 367. LargeAddressAware 옵션이 적용된 닷넷 32비트 프로세스의 가용 메모리
; https://www.sysnet.pe.kr/2/0/1441

.NET Framework: 640. 닷넷 - 배열 크기의 한계
; https://www.sysnet.pe.kr/2/0/11142

.NET Framework: 2105. LargeAddressAware 옵션이 적용된 닷넷 32비트 프로세스의 가용 메모리 - 두 번째
; https://www.sysnet.pe.kr/2/0/13294




.NET 4.5의 2GB 힙 한계 극복


예전에, 닷넷으로 64비트 응용 프로그램을 만든 경우 여전히 2GB 한계에 걸리는 문제를 설명한 적이 있습니다.

.NET 64비트 응용 프로그램에서 왜 (2GB) OutOfMemoryException 예외가 발생할까?
; https://www.sysnet.pe.kr/2/0/946

한 개의 "GC Heap" 자체가 2GB로 제한되어 있기 때문에 하나의 참조형 객체가 2GB 이상의 메모리를 사용할 수 없다는 제약이 있습니다. 물론, 전체적으로 보면 여러 개의 GC Heap을 생성하기 때문에 64비트 윈도우의 경우 운영체제가 허용하는 한 메모리를 사용할 수 있습니다.

이 제한이 .NET 4.5에서 풀렸습니다.

Large matrices and vectors
; http://www.centerspace.net/blog/nmath/large-matrices-and-vectors/

대신 명시적으로 2GB 이상의 힙 사용이 가능하도록 app.config에 <gcAllowVeryLargeObjects enabled="true" /> 옵션을 추가해야 합니다.

<?xml version="1.0"?>
<configuration>
  <runtime>
    <gcAllowVeryLargeObjects enabled="true" />
  </runtime>
</configuration>

테스트를 해볼까요? ^^ 메모리 할당을 무한정 가능하게 만들면 컴퓨터 반응속도가 너무 느려지므로 다음과 같이 for 문의 최대값을 2GB 한계만 좀 넘도록 조정해 보겠습니다.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            long i = 0;

            HashSet<long> t = new HashSet<long>();

            try
            {
                for (i = 0; i < 47995853 + (47995853 / 2); i++)
                {
                    t.Add(i);
                }
            }
            catch
            {
                Console.WriteLine("OOM: " + i);
            }

            Console.ReadLine();
        }
    }
}

이 프로그램을 .NET 4.0/x64 환경에서 구동하면 OOM 오류가 발생하겠지만, 변경된 app.config의 설정과 함께 .NET 4.5/x64에서 구동하면 정상적으로 HashSet 객체가 2GB를 넘어서 관리힙에 할당됩니다.

아래는 위의 프로그램을 실행한 후의 작업 관리자 메모리 상황입니다.

net45_large_gcheap_1.png

그 외에 ^^ .NET 4.5의 개선 사항을 다음의 글에서 참조하세요.

An Overview of Performance Improvements in .NET 4.5
; https://learn.microsoft.com/en-us/archive/msdn-magazine/2012/april/clr-an-overview-of-performance-improvements-in-net-4-5




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 3/22/2023]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... [76]  77  78  79  80  81  82  83  84  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
12037정성태10/15/201924461.NET Framework: 867. C# - Encoding.Default 값을 바꿀 수 있을까요?파일 다운로드1
12036정성태10/14/201925588.NET Framework: 866. C# - 고성능이 필요한 환경에서 GC가 발생하지 않는 네이티브 힙 사용파일 다운로드1
12035정성태10/13/201919717개발 환경 구성: 461. C# 8.0의 #nulable 관련 특성을 .NET Framework 프로젝트에서 사용하는 방법 [2]파일 다운로드1
12034정성태10/12/201919035개발 환경 구성: 460. .NET Core 환경에서 (프로젝트가 아닌) C# 코드 파일을 입력으로 컴파일하는 방법 [1]
12033정성태10/11/201923186개발 환경 구성: 459. .NET Framework 프로젝트에서 C# 8.0/9.0 컴파일러를 사용하는 방법
12032정성태10/8/201919316.NET Framework: 865. .NET Core 2.2/3.0 웹 프로젝트를 IIS에서 호스팅(Inproc, out-of-proc)하는 방법 - AspNetCoreModuleV2 소개
12031정성태10/7/201916693오류 유형: 569. Azure Site Extension 업그레이드 시 "System.IO.IOException: There is not enough space on the disk" 예외 발생
12030정성태10/5/201923529.NET Framework: 864. .NET Conf 2019 Korea - "닷넷 17년의 변화 정리 및 닷넷 코어 3.0" 발표 자료 [1]파일 다운로드1
12029정성태9/27/201924261제니퍼 .NET: 29. Jennifersoft provides a trial promotion on its APM solution such as JENNIFER, PHP, and .NET in 2019 and shares the examples of their application.
12028정성태9/26/201919310.NET Framework: 863. C# - Thread.Suspend 호출 시 응용 프로그램 hang 현상을 해결하기 위한 시도파일 다운로드1
12027정성태9/26/201914903오류 유형: 568. Consider app.config remapping of assembly "..." from Version "..." [...] to Version "..." [...] to solve conflict and get rid of warning.
12026정성태9/26/201920393.NET Framework: 862. C# - Active Directory의 LDAP 경로 및 정보 조회
12025정성태9/25/201918649제니퍼 .NET: 28. APM 솔루션 제니퍼, PHP, .NET 무료 사용 프로모션 2019 및 적용 사례 (8) [1]
12024정성태9/20/201920583.NET Framework: 861. HttpClient와 HttpClientHandler의 관계 [2]
12023정성태9/18/201921119.NET Framework: 860. ServicePointManager.DefaultConnectionLimit와 HttpClient의 관계파일 다운로드1
12022정성태9/12/201924959개발 환경 구성: 458. C# 8.0 (Preview) 신규 문법을 위한 개발 환경 구성 [3]
12021정성태9/12/201940768도서: 시작하세요! C# 8.0 프로그래밍 [4]
12020정성태9/11/201923952VC++: 134. SYSTEMTIME 값 기준으로 특정 시간이 지났는지를 판단하는 함수
12019정성태9/11/201917547Linux: 23. .NET Core + 리눅스 환경에서 Environment.CurrentDirectory 접근 시 주의 사항
12018정성태9/11/201916339오류 유형: 567. IIS - Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive. (D:\lowSite4\web.config line 11)
12017정성태9/11/201920087오류 유형: 566. 비주얼 스튜디오 - Failed to register URL "http://localhost:6879/" for site "..." application "/". Error description: Access is denied. (0x80070005)
12016정성태9/5/201920117오류 유형: 565. git fetch - warning: 'C:\ProgramData/Git/config' has a dubious owner: '(unknown)'.
12015정성태9/3/201925601개발 환경 구성: 457. 윈도우 응용 프로그램의 Socket 연결 시 time-out 시간 제어
12014정성태9/3/201919306개발 환경 구성: 456. 명령행에서 AWS, Azure 등의 원격 저장소에 파일 관리하는 방법 - cyberduck/duck 소개
12013정성태8/28/201922217개발 환경 구성: 455. 윈도우에서 (테스트) 인증서 파일 만드는 방법 [3]
12012정성태8/28/201926793.NET Framework: 859. C# - HttpListener를 이용한 HTTPS 통신 방법
... [76]  77  78  79  80  81  82  83  84  85  86  87  88  89  90  ...