Use SegmentStream.CreateWithoutOwningStream to avoid reading data into memory.

To avoid creating copied data in memory (e.g. via MemoryStream), this method can be used to reference offsets on files on disk, reducing memory requirements.
This commit is contained in:
RoosterDragon
2018-04-10 20:14:41 +01:00
committed by abcdefg30
parent 9a9bf441ba
commit b98123d9f8
3 changed files with 13 additions and 21 deletions

View File

@@ -13,6 +13,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using OpenRA.FileSystem;
using OpenRA.Primitives;
using FS = OpenRA.FileSystem.FileSystem;
namespace OpenRA.Mods.Cnc.FileSystem
@@ -69,9 +70,7 @@ namespace OpenRA.Mods.Cnc.FileSystem
if (!index.TryGetValue(filename, out entry))
return null;
stream.Seek(entry.Offset, SeekOrigin.Begin);
var data = stream.ReadBytes((int)entry.Length);
return new MemoryStream(data);
return SegmentStream.CreateWithoutOwningStream(stream, entry.Offset, (int)entry.Length);
}
public bool Contains(string filename)