Exemple #1
0
 private void SavePool(IndexBufferPool pool, string name, bool isBigEndian)
 {
     using (MemoryStream stream = new MemoryStream())
     {
         pool.WriteToFile(stream, isBigEndian);
         File.WriteAllBytes(name, stream.ToArray());
         loadedPoolNames.Add(new FileInfo(name));
     }
 }
Exemple #2
0
        public void ReadFiles(bool isBigEndian)
        {
            for (int i = 0; i != loadedPoolNames.Count; i++)
            {
                IndexBufferPool pool = null;
                using (MemoryStream stream = new MemoryStream(File.ReadAllBytes(loadedPoolNames[i].FullName), false))
                {
                    pool = new IndexBufferPool(stream, isBigEndian);
                }

                foreach (var buff in pool.Buffers)
                {
                    if (!buffers.ContainsKey(buff.Key))
                    {
                        buffers.Add(buff.Key, buff.Value);
                    }
                    else
                    {
                        Console.WriteLine("Skipped a buffer {0}", buff.Key);
                    }
                }
            }
        }
Exemple #3
0
        public void WriteToFile(bool isBigEndian = false)
        {
            int             numPool  = 0;
            int             poolSize = 0;
            IndexBufferPool pool     = new IndexBufferPool();

            foreach (var loaded in loadedPoolNames)
            {
                File.Delete(loaded.FullName);
            }
            loadedPoolNames.Clear();
            var buffArray = buffers.Values.ToArray();

            //var sorted = buffArray.OrderBy(buff => buff.Data.Length);
            foreach (var buffer in buffArray)
            {
                int prePoolSize = (poolSize) + (int)(buffer.GetLength());
                if (pool.Buffers.Count == 128 || prePoolSize > ToolkitSettings.IndexMemorySizePerBuffer)
                {
                    string name = Path.Combine(root.FullName, string.Format("IndexBufferPool_{0}.ibp", numPool));
                    SavePool(pool, name, isBigEndian);
                    pool = new IndexBufferPool();
                    numPool++;
                    prePoolSize = 0;
                }

                pool.Buffers.Add(buffer.Hash, buffer);
                poolSize = prePoolSize;
            }

            if (pool != null)
            {
                string name = Path.Combine(root.FullName, string.Format("IndexBufferPool_{0}.ibp", numPool));
                SavePool(pool, name, isBigEndian);
            }
        }