Ejemplo n.º 1
0
        /// <summary>
        /// 获取数据源
        /// </summary>
        /// <returns></returns>
        public dataSource Get()
        {
            dataSource value = new dataSource();

            value.Data    = stream.GetArray();
            value.Strings = strings.ToArray();
            value.Bytes   = bytes.ToArray();
            return(value);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 中文分词词语集合写入文本文件
 /// </summary>
 private unsafe static void writeTxtFile()
 {
     string[] words = Words;
     using (unmanagedStream wordStream = new unmanagedStream())
     {
         *(int *)wordStream.Data = words.Length;
         wordStream.UnsafeAddLength(sizeof(int));
         foreach (string word in words)
         {
             wordStream.Write(word);
             wordStream.Write((char)0);
         }
         subArray <byte> data = io.compression.stream.Deflate.GetCompress(wordStream.GetArray(), 0);
         using (FileStream fileStream = new FileStream(fastCSharp.config.search.Default.WordTxtFileName, FileMode.Create, FileAccess.Write, FileShare.None))
         {
             fileStream.Write(data.UnsafeArray, data.StartIndex, data.Count);
         }
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 保存TCP服务信息集合到缓存文件
        /// </summary>
        internal unsafe void SaveCacheFile()
        {
            cache cache = new cache();

            byte[] buffer = fastCSharp.memoryPool.StreamBuffers.Get();
            try
            {
                fixed(byte *bufferFixed = buffer)
                {
                    using (unmanagedStream stream = new unmanagedStream(bufferFixed, buffer.Length))
                    {
                        Monitor.Enter(serviceLock);
                        try
                        {
                            cache.Services  = serviceCache.Values.getArray();
                            cache.HostPorts = hostPorts.getArray(value => new keyValue <string, int>(value.Key.ToString(), value.Value));
                            fastCSharp.emit.dataSerializer.Serialize(cache, stream);
                            if (stream.data.data == bufferFixed)
                            {
                                using (FileStream file = new FileStream(cacheFile, FileMode.Create, FileAccess.Write, FileShare.None))
                                {
                                    file.Write(buffer, 0, stream.Length);
                                }
                            }
                            else
                            {
                                File.WriteAllBytes(cacheFile, stream.GetArray());
                            }
                        }
                        finally
                        {
                            isSaveCacheFile = 0;
                            Monitor.Exit(serviceLock);
                        }
                    }
                }
            }
            finally { fastCSharp.memoryPool.StreamBuffers.PushNotNull(buffer); }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 获取解压数据
 /// </summary>
 /// <returns>解压数据</returns>
 public unsafe subArray <byte> Get(memoryPool memoryPool)
 {
     if (memoryPool == null)
     {
         pointer data = fastCSharp.unmanagedPool.StreamBuffers.Get();
         try
         {
             using (dataStream = new unmanagedStream(data.Byte, fastCSharp.unmanagedPool.StreamBuffers.Size))
             {
                 get();
                 return(new subArray <byte>(dataStream.GetArray()));
             }
         }
         finally { fastCSharp.unmanagedPool.StreamBuffers.Push(ref data); }
     }
     else
     {
         byte[] data = memoryPool.Get();
         try
         {
             fixed(byte *dataFixed = data)
             {
                 using (dataStream = new unmanagedStream(dataFixed, data.Length))
                 {
                     get();
                     if (dataStream.data.data == dataFixed)
                     {
                         byte[] buffer = data;
                         data = null;
                         return(subArray <byte> .Unsafe(buffer, 0, dataStream.Length));
                     }
                     return(new subArray <byte>(dataStream.GetArray()));
                 }
             }
         }
         finally { memoryPool.PushOnly(data); }
     }
 }
 /// <summary>
 /// 获取解压数据
 /// </summary>
 /// <returns>解压数据</returns>
 public unsafe subArray<byte> Get(memoryPool memoryPool)
 {
     if (memoryPool == null)
     {
         pointer data = fastCSharp.unmanagedPool.StreamBuffers.Get();
         try
         {
             using (dataStream = new unmanagedStream(data.Byte, fastCSharp.unmanagedPool.StreamBuffers.Size))
             {
                 get();
                 return new subArray<byte>(dataStream.GetArray());
             }
         }
         finally { fastCSharp.unmanagedPool.StreamBuffers.Push(ref data); }
     }
     else
     {
         byte[] data = memoryPool.Get();
         try
         {
             fixed (byte* dataFixed = data)
             {
                 using (dataStream = new unmanagedStream(dataFixed, data.Length))
                 {
                     get();
                     if (dataStream.Data == dataFixed)
                     {
                         byte[] buffer = data;
                         data = null;
                         return subArray<byte>.Unsafe(buffer, 0, dataStream.Length);
                     }
                     return new subArray<byte>(dataStream.GetArray());
                 }
             }
         }
         finally { memoryPool.Push(ref data); }
     }
 }