Exemplo n.º 1
0
        public void CreateNewCreatesTwoDimensionalMatrixAndOpenCorrectlyReadIt()
        {
            const int size0 = 500;
            const int size1 = 20;

            var tempFileName = Path.GetTempFileName();

            try
            {
                File.Delete(tempFileName);

                long count;
                using (var array = MemoryMappedArray <double> .CreateNew(tempFileName, size0, size1))
                {
                    count = array.NumElements;

                    for (int i = 0; i < size0; i++)
                    {
                        for (int j = 0; j < size1; j++)
                        {
                            array[i, j] = (long)i * size1 + j;
                        }
                    }
                }

                using (var array = MemoryMappedArray <double> .Open(tempFileName))
                {
                    Assert.AreEqual(size0, array.Size0);
                    Assert.AreEqual(size1, array.Size1);
                    Assert.AreEqual(count, array.NumElements);

                    for (int i = 0; i < size0; i++)
                    {
                        for (int j = 0; j < size1; j++)
                        {
                            double v = (double)i * size1 + j;
                            Assert.AreEqual(v, array[i, j]);
                        }
                    }
                }
            }
            finally
            {
                File.Delete(tempFileName);
            }
        }
Exemplo n.º 2
0
        public void CreateNewCreatesOneDimensionalMatrixAndOpenCorrectlyReadIt()
        {
            const int length       = 100;
            var       tempFileName = Path.GetTempFileName();

            try
            {
                File.Delete(tempFileName);

                int  size0;
                int  size1;
                long count;
                using (var array = MemoryMappedArray <double> .CreateNew(tempFileName, length))
                {
                    size0 = array.Size0;
                    size1 = array.Size1;
                    count = array.NumElements;

                    for (int i = 0; i < length; i++)
                    {
                        array[i] = i;
                    }
                }

                using (var array = MemoryMappedArray <double> .Open(tempFileName))
                {
                    Assert.AreEqual(size0, array.Size0);
                    Assert.AreEqual(size1, array.Size1);
                    Assert.AreEqual(count, array.NumElements);

                    for (int i = 0; i < length; i++)
                    {
                        Assert.AreEqual(i, array[i]);
                    }
                }
            }
            finally
            {
                File.Delete(tempFileName);
            }
        }