-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVolume.cs
62 lines (49 loc) · 1.55 KB
/
Volume.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Diagnostics;
using System.IO;
namespace MappableFileStream
{
[DebuggerDisplay("{hs}")]
unsafe class Volume : DataSource
{
readonly IMappableFileStream<int> hs;
readonly int N;
string TempPath = "C:\\MMF";
static int Number=0;
public Volume(int sizex, int sizey, int sizez, string fileName = null)
{
SizeX = sizex;
SizeY = sizey;
SizeZ = sizez;
N = SizeX * SizeY;
if (!Directory.Exists(TempPath))
Directory.CreateDirectory(TempPath);
if (string.IsNullOrEmpty(fileName))
{
//Guid.NewGuid().ToString()
fileName = Path.Combine(TempPath, (Number++).ToString()) + ".tmp";
hs = MappableFileStream.CreateNew<int>(fileName, N, SizeZ);
}
else
{
//stream = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite, (int)SliceSize, FileOptions.RandomAccess);
}
}
public override void Dispose()
{
hs.Dispose();
}
public override ReadOnlySpan<int> GetData(int sliceIndex)
{
return hs.GetReadHandle(sliceIndex);
}
public void SetData(int sliceIndex, int[] data)
{
hs.Write(sliceIndex, data);
}
public Span<int> GetWriteHandle(int sliceIndex)
{
return hs.GetWriteHandle(sliceIndex);
}
}
}