Esempio n. 1
0
        public void Test()
        {
            var sink = new BufferSink <int>(10);

            var step = 7;

            for (int i = 0; 2048 > i; i += step)
            {
                var data = new int[step];
                for (int j = 0; j < step; j++)
                {
                    data[j] = i + j;
                }

                sink.PushCopied(data, 0, data.Length, false);
            }

            int index = 0;

            while (sink.IsFilled)
            {
                var buffer = sink.Pop();
                foreach (var element in buffer)
                {
                    Assert.AreEqual(index++, element);
                }
            }
        }
Esempio n. 2
0
        public float[] Next(int size)
        {
            if (size * 3 > sink.Size)
            {
                sink.Size = size * 3;
            }

            Task t = null;

            lock (sink)
            {
                if (!sink.IsFilled)
                {
                    FillSink();
                    t = currentFillTask;
                }
            }

            if (t != null)
            {
                t.Wait();
            }

            float[] buffer = null;
            lock (sink)
            {
                buffer = sink.Pop(size);
            }

            FillSink();
            return(buffer);
        }