Ejemplo n.º 1
0
        /// <summary>
        /// Tests writing to an array.
        /// </summary>
        public static void TestWrite(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                FileMode.Create, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array<int>(map, Global.ArrayTestLength,
                        profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Write Array: {0}", profile.ToString()), 
                            1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        array[i] = i * 2;

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Writing... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Tests read from an array.
        /// </summary>
        public static void TestRead(ArrayProfile profile)
        {
            using (var mapStream = new FileInfo(Global.FileName).Open(
                FileMode.Open, FileAccess.ReadWrite))
            {
                using (var map = new MemoryMapStream(mapStream))
                {
                    var array = new Array<int>(map.CreateInt32(mapStream.Length / 4), profile);

                    var perf = new PerformanceInfoConsumer(
                        string.Format("Read Array: {0}", profile.ToString()),
                            1000);
                    perf.Start();
                    for (var i = 0; i < array.Length; i++)
                    {
                        var val = array[i];
                        if (val != i * 2)
                        { // oeps, something went wrong here!
                            throw new System.Exception();
                        }

                        if (Global.Verbose && i % (array.Length / 100) == 0)
                        {
                            perf.Report("Reading... {0}%", i, array.Length - 1);
                        }
                    }
                    perf.Stop();

                    //var size = 1000000;
                    //perf = new PerformanceInfoConsumer(
                    //    string.Format("Read Random Array: {0} {1}", size, profile.ToString()),
                    //        1000);
                    //perf.Start();
                    //var rand = new Random();
                    //for (var i = 0; i < size; i++)
                    //{
                    //    var ran = (long)rand.Next((int)array.Length);
                    //    var val = array[ran];
                    //    if (val != ran * 2)
                    //    { // oeps, something went wrong here!
                    //        throw new System.Exception();
                    //    }

                    //    if (Global.Verbose && i % (size / 100) == 0)
                    //    {
                    //        perf.Report("Reading... {0}%", i, size);
                    //    }
                    //}
                    //perf.Stop();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a mapped array with the given size.
        /// </summary>
        public static ArrayBase <T> CreateFor(MemoryMap map, long size, ArrayProfile profile)
        {
            var func = MemoryMap.GetCreateAccessorFuncFor <T>();

            using (var accessor = func(map, 0))
            {
                if (accessor.ElementSizeFixed)
                { // fixed element size.
                    return(new Array <T>(map, size, profile));
                }
            }
            return(new VariableArray <T>(map, size));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a memory mapped array based on existing data.
 /// </summary>
 public Array(MappedAccessor <T> accessor, ArrayProfile profile)
     : this(accessor, profile.BufferSize, profile.CacheSize)
 {
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a memory mapped array.
 /// </summary>
 public Array(MemoryMap map, long length,
              ArrayProfile profile)
     : this(map, length, DefaultAccessorSize, profile.BufferSize, profile.CacheSize)
 {
 }