zoukankan      html  css  js  c++  java
  • 内存映射和独立存贮器

            #region 内存映射
            /// <summary>
            /// 内存映射
            /// </summary>
            static void MappingMemory()
            {
    
                using (var mmFile = MemoryMappedFile.CreateFromFile("d:mappingmemory.txt", FileMode.Create, "fileHandle", 1024 * 1024))
                {
                    string valueToWrite = "Written to the mapped-memory file on " + DateTime.Now.ToString();
                    var myAccessor = mmFile.CreateViewAccessor();
                    myAccessor.WriteArray<byte>(0, Encoding.ASCII.GetBytes(valueToWrite), 0, valueToWrite.Length);
                    var readOut = new byte[valueToWrite.Length];
                    myAccessor.ReadArray<byte>(0, readOut, 0, readOut.Length);
                    Console.WriteLine("The data is:" + Encoding.ASCII.GetString(readOut));
                    Console.ReadKey();
                }
            }
            #endregion
    
            #region 独立存贮器(用于数据处理) 
            static void UserIsolationFile()
            {
       
                IsolatedStorageFile storFile = IsolatedStorageFile.GetUserStoreForDomain();
                IsolatedStorageFileStream storStream = new IsolatedStorageFileStream("storagefile.txt", FileMode.Create, FileAccess.Write);
                StreamWriter writer = new StreamWriter(storStream);
                writer.WriteLine("You are dead!");
                writer.Flush();
                writer.Close();
                storStream.Close();
                storFile.Close();
                IsolatedStorageFile storFile2 = IsolatedStorageFile.GetUserStoreForDomain();
                string[] filenames = storFile2.GetFileNames();
                foreach (string filename in filenames)
                {
                    if (filename != "storagefile.txt")
                    {
                        continue;
                    }
                    using (IsolatedStorageFileStream stream = new
                IsolatedStorageFileStream("storagefile.txt", FileMode.Open))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            Console.WriteLine(reader.ReadToEnd());
                        }
                    }
    
                }
                Console.ReadKey();
            }
            #endregion
  • 相关阅读:

    Android自己主动化測试之Monkeyrunner用法及实例
    递归函数的概念使用方法与实例
    正则、grep、sed、awk
    我的java学习笔记(一)
    mysql经常使用命令总结
    JSP动作--JSP有三种凝视方式
    http长连接和短连接
    StirngUtil工具类 之 邮箱注冊 域名不区分大写和小写方法
    在Eclipse上搭建Cocos2d-x的Android开发环境
  • 原文地址:https://www.cnblogs.com/LiMin/p/3403863.html
Copyright © 2011-2022 走看看