[C#/COMMON] MemoryMappedFile 클래스 : CreateFromFile 정적 메소드를 사용해 메모리 매핑 파일 만들기
C#/Common 2022. 5. 25. 21:58728x90
반응형
728x170
▶ CustomColor.cs
using System;
namespace TestProject
{
/// <summary>
/// 커스텀 색상
/// </summary>
public struct CustomColor
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Public
#region Field
/// <summary>
/// 적색
/// </summary>
public short Red;
/// <summary>
/// 녹색
/// </summary>
public short Green;
/// <summary>
/// 청색
/// </summary>
public short Blue;
/// <summary>
/// 알파
/// </summary>
public short Alpha;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 밝게하기 - Brighten(value)
/// <summary>
/// 밝게하기
/// </summary>
/// <param name="value">값</param>
public void Brighten(short value)
{
Red = (short)Math.Min(short.MaxValue, (int)Red + value);
Green = (short)Math.Min(short.MaxValue, (int)Green + value);
Blue = (short)Math.Min(short.MaxValue, (int)Blue + value);
Alpha = (short)Math.Min(short.MaxValue, (int)Alpha + value);
}
#endregion
}
}
728x90
▶ Program.cs
using System.IO;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
namespace TestProject
{
/// <summary>
/// 프로그램
/// </summary>
class Program
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Static
//////////////////////////////////////////////////////////////////////////////// Private
#region 프로그램 시작하기 - Main()
/// <summary>
/// 프로그램 시작하기
/// </summary>
private static void Main()
{
string mapFilePath = "d:\\ExtremelyLargeImage.data";
string mapName = "testMap";
long dataOffset = 0x10000000; // 256MB
long dataLength = 0x20000000; // 512MB
long mapFileLength = 0x40000000; // 1GB
if(!File.Exists(mapFilePath))
{
using(MemoryMappedFile file = MemoryMappedFile.CreateFromFile(mapFilePath, FileMode.CreateNew, mapName, mapFileLength))
{
}
}
using(MemoryMappedFile file = MemoryMappedFile.CreateFromFile(mapFilePath, FileMode.Open, mapName))
{
using(MemoryMappedViewAccessor accessor = file.CreateViewAccessor(dataOffset, dataLength))
{
int colorSize = Marshal.SizeOf(typeof(CustomColor));
for (long i = 0; i < dataLength; i += colorSize)
{
accessor.Read(i, out CustomColor color);
color.Brighten(10);
accessor.Write(i, ref color);
}
}
}
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON/.NET6] Regex 클래스 : Replace 정적 메소드를 사용해 특수 문자 제거하기 (0) | 2022.06.20 |
---|---|
[C#/COMMON/.NET6] 룩업 테이블을 사용해 특수 문자 제거하기 (0) | 2022.06.20 |
[C#/COMMON/.NET6] 특수 문자 제거하기 (0) | 2022.06.20 |
[C#/COMMON/.NET6] MailAddress 클래스 : E 메일 주소 여부 구하기 (0) | 2022.06.20 |
[C#/COMMON/.NET6] Buffer 클래스 : BlockCopy 정적 메소드를 사용해 인코딩 배제 문자열 바이트 배열 구하기 (0) | 2022.06.20 |
[C#/COMMON] FileSystem 클래스 : CopyDirectory 정적 메소드를 사용해 디렉토리 복사하기 (0) | 2022.05.25 |
[C#/COMMON] Marshal 클래스 : Copy 정적 메소드를 사용해 문자열을 fixed char 필드에 복사하기 (0) | 2022.05.25 |
[C#/COMMON] DynamicMethod 클래스 : Invoke 메소드를 사용해 구조체 크기 구하기 (0) | 2022.05.25 |
[C#/COMMON] MemoryMappedFile 클래스 : CreateNew 정적 메소드를 사용해 시스템 메모리에서 메모리 매핑 파일 만들기 (0) | 2022.05.25 |
[C#/COMMON/.NET5] 콘솔 폰트 설정하기 (0) | 2022.05.24 |
댓글을 달아 주세요