コード例 #1
0
ファイル: SolidKeyValueStorage.cs プロジェクト: vebin/BD2
 void Initialize()
 {
     if (!Directory.Exists (path.Path))
         Directory.CreateDirectory (path.Path);
     string blockFileName = path.CreatePath (name).Path;
     Console.WriteLine ("Name: {0}", name);
     Console.WriteLine ("Block: {0}", blockFileName);
     bool blockExists = File.Exists (blockFileName);
     if (!blockExists) {
         FileStream fs;
         fs = File.Open (blockFileName, FileMode.OpenOrCreate);
         if ((capacity = fs.Length) == 0) {
             fs.SetLength (capacity = 0x100000);
             fs.WriteByte (0);
             fs.WriteByte (0);
             fs.WriteByte (1);//65536
             fs.WriteByte (0);
             fs.WriteByte (0);
             fs.WriteByte (0);
             fs.WriteByte (0);
             fs.WriteByte (0);
         }
         fs.Close ();
     }
     mmfBlock = MemoryMappedFile.CreateFromFile (blockFileName, FileMode.Open);
     maData = mmfBlock.CreateViewStream ();
     offset = (long)
         (((ulong)maData.ReadByte ()) |
     ((ulong)maData.ReadByte ()) << 8 |
     ((ulong)maData.ReadByte ()) << 16 |
     ((ulong)maData.ReadByte ()) << 24 |
     ((ulong)maData.ReadByte ()) << 32 |
     ((ulong)maData.ReadByte ()) << 40 |
     ((ulong)maData.ReadByte ()) << 48 |
     ((ulong)maData.ReadByte ()) << 56);
 }