예제 #1
0
        public void Test_Serialize() {
            int errorCode = 0;
            try {
                double[] data = new double[1000 * 1000 * 10];
                String filename = "ILDoubleArray_SerializeTest1.ils";
                for (int i = 0; i < data.Length; i++)
                    data[i] = (double)i;
                ILArray<double> A = new ILArray<double>(data, 1000,1000,10);

                FileStream fs = new FileStream(filename, FileMode.Create);
                Info("Serializing to file: (please wait...)");
                A.Serialize(fs); 
                fs.Close();
                FileInfo fi = new FileInfo(filename);
                Info("Serialized to file: [1000 x 1000 x 10] => " + ((int)(fi.Length/1024)) + "kB");
                
                // create reference storage from smaler range -> should Detach()  
                errorCode = 1;
                filename = "ILDoubleArray_SerializeTest2.ils";
                fs = new FileStream(filename, FileMode.Create);
                ILArray<double> AR1 = (ILArray<double>)A[0,"0:600;30:400;0:end"];
                AR1.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [600 x 360 x 10] => " + ((int)(fi.Length / 1024)) + "kB");

                // if reference storage saved effective memory - keep it as reference
                errorCode = 2;
                filename = "ILDoubleArray_SerializeTest3.ils";
                fs = new FileStream(filename, FileMode.Create);
                ILArray<double> AR2 = (ILArray<double>)A[0,"0:end,0:end;0:end,0:end;0:end"];
                AR2.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [2000 x 2000 x 20] => " + ((int)(fi.Length / 1024)) + "kB");


                // test if small reference would NOT store full data array
                errorCode = 4;
                filename = "ILDoubleArray_SerializeTest4.ils";
                fs = new FileStream(filename, FileMode.Create);
                ILArray<double> AR3 = (ILArray<double>)A["3;3;1"];
                AR3.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [1 x 1] => " + ((int)(fi.Length / 1024)) + "kB");
                if (fi.Length > 1024 * 2)
                    throw new Exception("Small reference storages should get detached before serializing!");
                errorCode = 5;

                Success("Test_serialize successfull");
            } catch (SerializationException e) {
                Error("Test_serialize failed on ErrorCode: "+ errorCode +"due: " + e.Message);
            } catch (Exception e) {
                Error("Test_serialize failed on ErrorCode: " + errorCode + "due: " + e.Message);
            }
        }
예제 #2
0
        public void Test_Serialize()
        {
            int errorCode = 0;

            try {
                double[] data     = new double[1000 * 1000 * 10];
                String   filename = "ILDoubleArray_SerializeTest1.ils";
                for (int i = 0; i < data.Length; i++)
                {
                    data[i] = (double)i;
                }
                ILArray <double> A = new ILArray <double>(data, 1000, 1000, 10);

                FileStream fs = new FileStream(filename, FileMode.Create);
                Info("Serializing to file: (please wait...)");
                A.Serialize(fs);
                fs.Close();
                FileInfo fi = new FileInfo(filename);
                Info("Serialized to file: [1000 x 1000 x 10] => " + ((int)(fi.Length / 1024)) + "kB");

                // create reference storage from smaler range -> should Detach()
                errorCode = 1;
                filename  = "ILDoubleArray_SerializeTest2.ils";
                fs        = new FileStream(filename, FileMode.Create);
                ILArray <double> AR1 = (ILArray <double>)A[0, "0:600;30:400;0:end"];
                AR1.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [600 x 360 x 10] => " + ((int)(fi.Length / 1024)) + "kB");

                // if reference storage saved effective memory - keep it as reference
                errorCode = 2;
                filename  = "ILDoubleArray_SerializeTest3.ils";
                fs        = new FileStream(filename, FileMode.Create);
                ILArray <double> AR2 = (ILArray <double>)A[0, "0:end,0:end;0:end,0:end;0:end"];
                AR2.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [2000 x 2000 x 20] => " + ((int)(fi.Length / 1024)) + "kB");


                // test if small reference would NOT store full data array
                errorCode = 4;
                filename  = "ILDoubleArray_SerializeTest4.ils";
                fs        = new FileStream(filename, FileMode.Create);
                ILArray <double> AR3 = (ILArray <double>)A["3;3;1"];
                AR3.Serialize(fs);
                fs.Close();
                fi = new FileInfo(filename);
                Info("Serialized to file: [1 x 1] => " + ((int)(fi.Length / 1024)) + "kB");
                if (fi.Length > 1024 * 2)
                {
                    throw new Exception("Small reference storages should get detached before serializing!");
                }
                errorCode = 5;

                Success("Test_serialize successfull");
            } catch (SerializationException e) {
                Error("Test_serialize failed on ErrorCode: " + errorCode + "due: " + e.Message);
            } catch (Exception e) {
                Error("Test_serialize failed on ErrorCode: " + errorCode + "due: " + e.Message);
            }
        }