/// <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> /// 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> /// Read memory-mapped file from a file with the mode, and result is an AType. /// </summary> /// <param name="memoryMappadFilePath"></param> /// <param name="memoryMappedFileMode"></param> /// <returns></returns> public AType Read(string memoryMappadFilePath, MemoryMappedFileMode memoryMappedFileMode) { MemoryMappedFile memoryMappedFile; GetMemoryMappedFile(memoryMappadFilePath, out memoryMappedFile); return(MappedFile.Read(memoryMappedFile, memoryMappedFileMode)); }
/// <summary> /// Bind a memory-mapped file to a MappedFile instance. /// </summary> /// <param name="memoryMappedFile"></param> /// <param name="memoryMappedFileMode"></param> /// <returns></returns> public static AType Read(MemoryMappedFile memoryMappedFile, MemoryMappedFileMode memoryMappedFileMode) { MappedFile mappedFile = new MappedFile(memoryMappedFile, memoryMappedFileMode); return(mappedFile.Rank > 0 ? MMAArray.Create(mappedFile) : mappedFile.Reader(MappedFileInfo.HeaderSize)); }
/// <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); }
private MMAFloat(long position, MappedFile mappedFile) : base() { this.position = position; this.mappedFile = mappedFile; }
private static AType Create(MappedFile mappedFile, int depth, long position) { return new AReference(new MMAArray(mappedFile, depth, position)); }
public new static AType Create(MappedFile mappedFile) { return new AReference(new MMAArray(mappedFile)); }
private MMAArray(MappedFile mappedFile, int depth = 0) : this(mappedFile, depth, MappedFileInfo.HeaderSize) { }
private MMAArray(MappedFile mappedFile, int depth, long position) : base(ATypes.AArray) { this.mappedFile = mappedFile; this.items = new ConditionalWeakTable<ValueType, AType>(); this.indexCache = new Dictionary<int, ValueType>(); this.depth = depth; this.offset = position; }
public static AType Create(long position, MappedFile mappedFile) { return MMAChar.Create(position, mappedFile); }
public static AType Create(MappedFile mappedFile) { return MMAArray.Create(mappedFile); }
/// <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; }
public new static AType Create(long position, MappedFile mappedFile) { return new AReference(new MMAFloat(position, mappedFile)); }
/// <summary> /// Bind a memory-mapped file to a MappedFile instance. /// </summary> /// <param name="memoryMappedFile"></param> /// <param name="memoryMappedFileMode"></param> /// <returns></returns> public static AType Read(MemoryMappedFile memoryMappedFile, MemoryMappedFileMode memoryMappedFileMode) { MappedFile mappedFile = new MappedFile(memoryMappedFile, memoryMappedFileMode); return mappedFile.Rank > 0 ? MMAArray.Create(mappedFile) : mappedFile.Reader(MappedFileInfo.HeaderSize); }
private MMAInteger(long position, MappedFile mappedFile) : base() { this.position = position; this.mappedFile = mappedFile; }