예제 #1
0
        public override int Read(byte[] buffer, int offset, int count)
        {
            CheckDisposed();
            byte[] buf = buffer;
            if (offset != 0)
            {
                buf = ArraysReuseManager.ReuseOrGetNew <byte>(count);
            }

            IntPtr red = Marshal.AllocCoTaskMem(sizeof(int));

            try
            {
                stream.Read(buf, count, red);
                var redint = Marshal.ReadInt32(red);
                if (offset != 0)
                {
                    Array.Copy(buf, 0, buffer, offset, redint);
                    buf.Release();
                }
                return(redint);
            }
            finally
            {
                Marshal.FreeCoTaskMem(red);
            }
        }
예제 #2
0
 public ColorMap(int width, int height, int bits = 0, int?stride = null)
 {
     this.bits   = bits;
     this.stride = stride ?? width;
     this.height = height;
     this.width  = width;
     Values      = Arrays.CreateRepeat(height, () => ArraysReuseManager.ReuseOrGetNew <T>(Stride));
 }
예제 #3
0
        public void TestArrayReuse()
        {
            var stopwatch = Stopwatch.StartNew();

            for (var n = 0; n < testCount; n++)
            {
                for (var i = 0; i < arrayNumber; i++)
                {
                    var arr = ArraysReuseManager.ReuseOrGetNew <byte>(arraySize);
                    //for (var j = 0; j < arraySize; j++) arr[j] = (byte)(j & 255);
                    arr.Release();
                }
            }
            stopwatch.Stop();
            Console.WriteLine("TestArrayReuse: " + stopwatch.ElapsedMilliseconds / 1000.0 + "s");
        }