Skip to content

Commit

Permalink
Increase the I/O buffer size to 81920 bytes
Browse files Browse the repository at this point in the history
This significantly reduces the number of read and write calls when
reading large files.
81920 is the largest multiple of 4096 that is under the large object
heap limit (85,000 bytes).
  • Loading branch information
0xC0000054 committed Aug 26, 2021
1 parent 437ce4f commit 984d10b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions RawFileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public sealed class RawFileType : FileType
private static readonly string ExecutablePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dcraw_emu.exe");
private static readonly string OptionsFilePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "RawFileTypeOptions.txt");

private const int BufferSize = 4096;

public RawFileType() : base(
"RAW File",
FileTypeFlags.SupportsLoading,
Expand Down Expand Up @@ -118,10 +116,12 @@ protected override Document OnLoad(Stream input)
try
{
// Write the input stream to a temporary file for LibRaw to load.
using (FileStream output = new FileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.None, BufferSize))
using (FileStream output = new FileStream(tempFile, FileMode.Create, FileAccess.Write, FileShare.None))
{
output.SetLength(input.Length);
byte[] buffer = new byte[BufferSize];

// 81920 is the largest multiple of 4096 that is under the large object heap limit (85,000 bytes).
byte[] buffer = new byte[81920];

int bytesRead;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
Expand Down

0 comments on commit 984d10b

Please sign in to comment.