Esempio n. 1
0
        /// <summary>
        /// Changes the length of the stream.
        /// </summary>
        /// <param name="value"></param>
        /// <remarks>
        /// If <paramref name="value"/> is less than the current length of the
        /// stream, the data is truncated; otherwise, additional (undefined)
        /// elements are added to the end of the collection.
        /// </remarks>
        public override void SetLength(long value)
        {
            lock (syncLock) {
                long diff = _data.LongCount - value;

                if (diff > 0)
                {
                    // truncate end
                    _data.RemoveRange(value, diff);
                }
                else if (diff < 0)
                {
                    // pad end
                    _data.Grow(-diff);
                }
            }
        }
Esempio n. 2
0
        public void TestMemoryNc()
        {
            LinkedList <NcByteCollection> instances = new LinkedList <NcByteCollection>();
            int count = 0;

            while (true)
            {
                try {
                    NcByteCollection data = new NcByteCollection(8 * 4096);
                    data.Grow(10 * 1024 * 1024);
                    instances.AddLast(data);
                    count++;
                }
                catch (OutOfMemoryException) {
                    Console.WriteLine("Collections allocated: {0}", count);
                    break;
                }
            }
            instances.Clear();
            instances = null;
            GC.Collect();
            GC.WaitForPendingFinalizers();
        }