Beispiel #1
0
        /// <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>
        /// 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();
        }
Beispiel #3
0
        /// <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));
        }
Beispiel #4
0
        /// <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));
        }
Beispiel #5
0
        /// <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));
        }
Beispiel #6
0
        /// <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);
        }
Beispiel #7
0
 private MMAFloat(long position, MappedFile mappedFile)
     : base()
 {
     this.position = position;
     this.mappedFile = mappedFile;
 }
Beispiel #8
0
 private static AType Create(MappedFile mappedFile, int depth, long position)
 {
     return new AReference(new MMAArray(mappedFile, depth, position));
 }
Beispiel #9
0
 public new static AType Create(MappedFile mappedFile)
 {
     return new AReference(new MMAArray(mappedFile));
 }
Beispiel #10
0
 private MMAArray(MappedFile mappedFile, int depth = 0)
     : this(mappedFile, depth, MappedFileInfo.HeaderSize)
 {
 }
Beispiel #11
0
 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;
 }
Beispiel #12
0
 public static AType Create(long position, MappedFile mappedFile)
 {
     return MMAChar.Create(position, mappedFile);
 }
Beispiel #13
0
 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;
        }
Beispiel #16
0
 public new static AType Create(long position, MappedFile mappedFile)
 {
     return new AReference(new MMAFloat(position, mappedFile));
 }
Beispiel #17
0
        /// <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);
        }
Beispiel #18
0
 private MMAInteger(long position, MappedFile mappedFile)
     : base()
 {
     this.position = position;
     this.mappedFile = mappedFile;
 }