Both stand-alone and mapped memory are used to handle program data problems. Independent storage can be used to temporarily save some of the program's unimportant data, mapped memory files can be used to solve the program data reading problems. When a program needs to load a large amount of external data in the process of running, it is a good choice to use it as a data cache area.
Independent storage
static void Userisolationfile () {//this file is saved into the path:c:\users\you Account\appdata\loc
Al\isolatedstorage 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 (); }
Mapping memory
How does this thing feel like C ah, haha. If a program requires frequent read and write text class files can this it to do a read-write cache to improve the efficiency of the program.
static void Mappingmemory ()
{
using (var mmfile=memorymappedfile.createfromfile ("D:\\mappingmemory.txt")
, FileMode.Create
, "FileHandle", 1024*1024))
{
String valuetowrite = ' written to ' 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 ();
}