์กฐ๊ธ ๋ ๋ค๋ฅธ ์ ๊ทผ์ ํด๋ดค์ต๋๋ค. ๋ง์ฝ, MemoryMappedFile
์ ์ด์ฉํด Span<byte>
์ ํ๋ํ ์ ๋ง ์๋ค๋ฉด, ์ข ๋ ํจ์จ์ ์ธ ๋๋ ๋ฐ์ดํฐ๋ฅผ ๋น ๋ฅด๊ฒ ์ฒ๋ฆฌํ ์ ์์๊บผ๋ผ ์๊ฐํ์ต๋๋ค.
ํ์ธํ ๊ฒฐ๊ณผ, ์ด์ฉ ์ ์์ด unsafe
์์ญ์ ์ฌ์ฉํด์ผ ํ๊ณ , decimal
์ด ๊ณ ์ ๋ฐฐ์ด์ด ์๋๋ค๋ ์ฌ์ค๋ ์๊ฒ ๋์์ง๋ง, ์ด์จ๋ ์๋นํ ๋น ๋ฅธ ์๋๋ก ๋ชฉ๋ก(Span<์ค์๊ฐ์์ธ2>
)์ ์์ฑํ ์ ์์์ต๋๋ค.
void ์์์์ธ๋ชฉ๋ก_์ฝ๊ธฐ2()
{
var filename = "์ค์๊ฐ์์ธ.dat";
var fileLength = new FileInfo(filename).Length;
using var mmf = MemoryMappedFile.CreateFromFile(filename, FileMode.Open);
using var accessor = mmf.CreateViewAccessor();
Span<byte> memory;
unsafe
{
byte* ptr = null;
accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref ptr);
ptr += accessor.PointerOffset;
//memory = new Span<byte>(ptr, (int)accessor.SafeMemoryMappedViewHandle.ByteLength);
memory = new Span<byte>(ptr, (int)fileLength);
}
var ์ค์๊ฐ์์ธ๋ชฉ๋ก = MemoryMarshal.Cast<byte, ์ค์๊ฐ์์ธ2>(memory);
foreach (var item in ์ค์๊ฐ์์ธ๋ชฉ๋ก)
{
;
}
accessor.SafeMemoryMappedViewHandle.ReleasePointer();
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
unsafe struct ์ค์๊ฐ์์ธ2
{
public long ์ฒด๊ฒฐ์๊ฐ;
public decimal ์ฒด๊ฒฐ๊ฐ;
public decimal ์ฒด๊ฒฐ์๋;
public fixed int _๋งค์ํธ๊ฐ์๋[4 * 5];
public fixed int _๋งค๋ํธ๊ฐ์๋[4 * 5];
}