Пример #1
0
 public void MultiString_Direct_Equals_01()
 {
     for (int j = 0; j < 21; j++)
     {
         var targetString  = j < 20 ? j.ToString() : "x"; // something not found for the last iteration
         var cap           = new CharArrayPool();
         var intPool       = new ColumnPool <int>();
         var shortPool     = new ColumnPool <short>();
         var bitvectorPool = new ColumnPool <long>(1 + (Config.DataBatchSize >> 6));
         var ms            = new MultiString(cap, intPool, shortPool, bitvectorPool);
         var input         = new string[20];
         for (int i = 0; i < 20; i++)
         {
             var s = i.ToString();
             input[i] = s;
             ms.AddString(s);
         }
         ms.Seal();
         bitvectorPool.Get(out var inBV);
         var result = ms.Equals(targetString, inBV, false);
         var output = new List <string>();
         for (int i = 0; i < 20; i++)
         {
             if ((result.col[i >> 6] & (1L << (i & 0x3f))) == 0)
             {
                 output.Add(ms[i]);
             }
         }
         var expected = input.Where(e => e.Equals(targetString));
         Assert.IsTrue(expected.SequenceEqual(output));
     }
 }
Пример #2
0
 public CharArrayWrapper(CharArrayPool pool, int size, int requestedSize)
 {
     this.UsedLength = requestedSize;
     this.pool       = pool;
     this.charArray  = new CharArray(size);
     this.RefCount   = 1;
 }
Пример #3
0
        private MyStringBuilder(MyStringBuilder from)
        {
            this.m_ChunkLength   = from.m_ChunkLength;
            this.m_ChunkOffset   = from.m_ChunkOffset;
            this.m_ChunkChars    = from.m_ChunkChars;
            this.m_ChunkPrevious = from.m_ChunkPrevious;
            this.m_MaxCapacity   = from.m_MaxCapacity;

            this.m_ChunkCharsWrapper = from.m_ChunkCharsWrapper;
            this.cap = from.cap;
        }
Пример #4
0
        public CharArrayWrapper Decode_CharArrayWrapper()
        {
            int header     = DecodeInt();
            int usedLength = DecodeInt();
            int length     = DecodeInt();

            if (charArrayPool == null)
            {
                charArrayPool = MemoryManager.GetCharArrayPool();
            }
            CharArrayWrapper result;

            if (usedLength == 0)
            {
                charArrayPool.Get(out result, 1);
            }
            else
            {
                charArrayPool.Get(out result, usedLength);
            }

            if (header == 0)
            {
                var buffer = AllocateColumnBatch <byte>(result.UsedLength * sizeof(char));
                FromStream(result.charArray.content, result.UsedLength, buffer.col);
                buffer.Return();
            }
            else
            {
                if (bytePool == null)
                {
                    bytePool = MemoryManager.GetDoublingArrayPool <byte>();
                }

                var    encodedSize = DecodeInt();
                byte[] buffer;

                if (encodedSize > 0)
                {
                    bytePool.Get(out buffer, encodedSize);
                }
                else
                {
                    bytePool.Get(out buffer, 1);
                }

                this.stream.ReadAllRequiredBytes(buffer, 0, encodedSize);
                Encoding.UTF8.GetChars(buffer, 0, encodedSize, result.charArray.content, 0);
                bytePool.Return(buffer);
            }

            return(result);
        }
Пример #5
0
        public unsafe MyStringBuilder(string value, int startIndex, int length, int capacity, CharArrayPool pool = null)
        {
            this.cap = pool;

            if (capacity < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(capacity));
            }
            else if (length < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }
            else if (startIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(startIndex));
            }
            else if (value == null)
            {
                value = string.Empty;
            }
            else if (startIndex > (value.Length - length))
            {
                throw new ArgumentOutOfRangeException(nameof(length));
            }

            this.m_MaxCapacity = 0x7fffffff;
            if (capacity == 0)
            {
                capacity = 0x10;
            }

            if (capacity < length)
            {
                capacity = length;
            }

            if (this.cap != null)
            {
                this.cap.Get(out this.m_ChunkCharsWrapper, capacity);
                this.m_ChunkChars = this.m_ChunkCharsWrapper.charArray.content;
            }
            else
            {
                this.m_ChunkChars = new char[capacity];
            }

            this.m_ChunkLength = length;
            fixed(char *str = value)
            {
                ThreadSafeCopy(str + startIndex, this.m_ChunkChars, 0, length);
            }
        }
Пример #6
0
        // TODO: Add more pools, there are still stuff that gets allocated.

        /// <summary>
        /// Initializes the pool factory with the given pool configuration.
        /// Will instantiate the pools, but not start them unless configuration says so.
        /// </summary>
        /// <param name="configuration">the configuration.</param>
        public PoolFactory(PoolConfiguration configuration)
        {
            int arraySize                 = 90000;
            var charArrayPool             = new CharArrayPool((int)(10 * arraySize * PoolFactor), (int)(arraySize * PoolFactor), configuration.PrefillPools);
            var asyncLogEventInfoListPool = new AsyncLogEventInfoListPool(5, (int)(10 * PoolFactor), configuration.PrefillPools);

            this.AddPool(charArrayPool, configuration);
            this.AddPool(asyncLogEventInfoListPool, configuration);
            this.AddPool(new ByteArrayPool((int)(10 * arraySize * PoolFactor), (int)(arraySize * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new StringBuilderPool((int)(10 * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new SingleCallContinuationPool((int)(10 * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new LogEventInfoPool((int)(10 * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new FileNameDictionaryPool(asyncLogEventInfoListPool, 10, 5, configuration.PrefillPools), configuration);
            this.AddPool(new AsyncContinuationListPool(10, configuration.PrefillPools), configuration);
            this.AddPool(new CombinedAsyncContinuationPool((int)(10 * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new GenericPool <Counter>((int)(10 * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new GenericPool <ContinueWhenAll>((int)(10 * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new ExceptionHandlerPool((int)(10 * PoolFactor), configuration.PrefillPools), configuration);
            this.AddPool(new AsyncLogEventInfoArrayPool((int)(10 * arraySize * PoolFactor), (int)(arraySize * PoolFactor)), configuration);
            this.AddPool(new MemoryStreamPool((int)(10 * PoolFactor)), configuration);
        }
Пример #7
0
 /// <summary>
 /// Gets a char[] instance from a common object pool.
 /// </summary>
 /// <param name="minimumCapacity">the minimum capacity of the returned char array.</param>
 /// <remarks>
 /// You are expected to call the Dispose method on the returned PooledObjectWrapper instance
 /// when you are done with the char[]. Calling Dispose returns the char[] to the
 /// pool.
 /// </remarks>
 public static PooledObjectWrapper <char[]> GetCharArray(int minimumCapacity)
 {
     return(CharArrayPool.GetInstance(minimumCapacity));
 }
Пример #8
0
 public MyStringBuilder(string value, int capacity, CharArrayPool pool = null)
     : this(value, 0, (value != null) ? value.Length : 0, capacity, pool)
 {
 }
Пример #9
0
 public MyStringBuilder(int capacity, CharArrayPool pool = null) : this(string.Empty, capacity, pool)
 {
 }
Пример #10
0
 public MyStringBuilder(CharArrayPool pool) : this(DefaultCapacity, pool)
 {
 }