/// <summary> /// Increase or decreade the size of a memory-mapped file. /// </summary> /// <param name="memoryMappedFilePath"></param> /// <param name="newLeadingAxesLength"></param> /// <returns></returns> public AType ExpandOrDecrease(string memoryMappedFilePath, int newLeadingAxesLength) { string memoryMappedFileName = EncodeName(memoryMappedFilePath); var memoryMappedFile = MemoryMappedFile.CreateFromFile(memoryMappedFilePath, FileMode.Open, memoryMappedFileName); MappedFile mappedFile = new MappedFile(memoryMappedFile); int newSize = mappedFile.ComputeNewSize(newLeadingAxesLength); int oldLeadingAxesLength = mappedFile.LeadingAxes; if (mappedFile.LeadingAxes < newLeadingAxesLength) { mappedFile.LeadingAxes = newLeadingAxesLength; mappedFile.Dispose(); memoryMappedFile = MemoryMappedFile.CreateFromFile(memoryMappedFilePath, FileMode.Open, memoryMappedFileName, newSize); memoryMappedFile.Dispose(); } else if (newLeadingAxesLength < mappedFile.LeadingAxes) { mappedFile.LeadingAxes = mappedFile.Length = newLeadingAxesLength; mappedFile.Dispose(); FileStream fileStream = new FileStream(memoryMappedFilePath, FileMode.Open); fileStream.SetLength(newSize); fileStream.Close(); } return(AInteger.Create(oldLeadingAxesLength)); }
/// <summary> /// Create a memory-mapped file with the given path and argument. /// </summary> /// <param name="path"></param> /// <param name="argument"></param> public void CreateMemmoryMappedFile(string path, AType argument) { GC.Collect(); GC.WaitForPendingFinalizers(); string memoryMappedFileName = EncodeName(path); MemoryMappedFile memoryMappedFile; try { memoryMappedFile = MemoryMappedFile.CreateFromFile( new FileStream(path, FileMode.Create), memoryMappedFileName, MappedFile.ComputeSize(argument), MemoryMappedFileAccess.ReadWrite, new MemoryMappedFileSecurity(), HandleInheritability.Inheritable, false ); } catch (Exception) { throw new Error.Invalid("MemoryMappedFile"); } MappedFile mappedFile = new MappedFile(memoryMappedFile); mappedFile.Create(argument); mappedFile.Dispose(); }
/// <summary> /// It gives back the leading axes (_Items function modify this value) of a memory-mapped file. /// </summary> /// <param name="memoryMappedFilePath"></param> /// <returns></returns> public AType GetLeadingAxesLength(string memoryMappedFilePath) { MemoryMappedFile memoryMappedFile; GetMemoryMappedFile(memoryMappedFilePath, out memoryMappedFile); MappedFile mappedFile = new MappedFile(memoryMappedFile); AType result = AInteger.Create(mappedFile.LeadingAxes); mappedFile.Dispose(); return(result); }
/// <summary> /// Increase or decreade the size of a memory-mapped file. /// </summary> /// <param name="memoryMappedFilePath"></param> /// <param name="newLeadingAxesLength"></param> /// <returns></returns> public AType ExpandOrDecrease(string memoryMappedFilePath, int newLeadingAxesLength) { string memoryMappedFileName = EncodeName(memoryMappedFilePath); var memoryMappedFile = MemoryMappedFile.CreateFromFile(memoryMappedFilePath, FileMode.Open, memoryMappedFileName); MappedFile mappedFile = new MappedFile(memoryMappedFile); int newSize = mappedFile.ComputeNewSize(newLeadingAxesLength); int oldLeadingAxesLength = mappedFile.LeadingAxes; if (mappedFile.LeadingAxes < newLeadingAxesLength) { mappedFile.LeadingAxes = newLeadingAxesLength; mappedFile.Dispose(); memoryMappedFile = MemoryMappedFile.CreateFromFile(memoryMappedFilePath, FileMode.Open, memoryMappedFileName, newSize); memoryMappedFile.Dispose(); } else if (newLeadingAxesLength < mappedFile.LeadingAxes) { mappedFile.LeadingAxes = mappedFile.Length = newLeadingAxesLength; mappedFile.Dispose(); FileStream fileStream = new FileStream(memoryMappedFilePath, FileMode.Open); fileStream.SetLength(newSize); fileStream.Close(); } return AInteger.Create(oldLeadingAxesLength); }
/// <summary> /// It gives back the leading axes (_Items function modify this value) of a memory-mapped file. /// </summary> /// <param name="memoryMappedFilePath"></param> /// <returns></returns> public AType GetLeadingAxesLength(string memoryMappedFilePath) { MemoryMappedFile memoryMappedFile; GetMemoryMappedFile(memoryMappedFilePath, out memoryMappedFile); MappedFile mappedFile = new MappedFile(memoryMappedFile); AType result = AInteger.Create(mappedFile.LeadingAxes); mappedFile.Dispose(); return result; }