Beispiel #1
0
        /// <summary>
        /// Causes an unallocated message to point at empty valid data
        /// </summary>
        /// <param name="tag">indication of why the allocation was done, for tracing reasons</param>
        public void Allocate(AllocationReason tag)
        {
            Debug.Assert(this.Unallocated);

            // acquire from a shared queue.
            this.payload = ThreadLocalMessageBufferPools <TRecord> .pool.Value.CheckOut(DEFAULT_MESSAGE_LENGTH);

            //ThreadLocalAllocationCounters<TRecord>.Increment(tag);
        }
Beispiel #2
0
        /// <summary>
        /// Releases the memory held by an allocated message back to a pool. Only call when no other references to the message are held.
        /// </summary>
        /// <param name="tag">indication of why the release was done, for tracing reasons</param>
        public void Release(AllocationReason tag)
        {
            Debug.Assert(!this.Unallocated);

            Array.Clear(this.payload, 0, this.length);

            // return to a shared queue.
            ThreadLocalMessageBufferPools <TRecord> .pool.Value.CheckIn(this.payload);

            //ThreadLocalAllocationCounters<TRecord>.Decrement(tag);

            this.payload = null;
            this.length  = 0;
        }
Beispiel #3
0
        public static void Increment(AllocationReason tag)
        {
            var dictionary = Counters.Value;

            if (!dictionary.ContainsKey(tag))
            {
                dictionary.Add(tag, new Pair <Int64, Int64>(0, 0));
            }

            var pair = dictionary[tag];

            pair.Second++;

            if (Math.Abs(pair.Second) > Math.Abs(pair.First) * 2 || Math.Abs(pair.Second) < Math.Abs(pair.First) / 2)
            {
                if (Math.Abs(pair.Second) > 256)
                {
                    Console.WriteLine("{0} Allocations; {1}, {2}", pair.Second, tag, typeof(T).GetHashCode());
                    pair.First = pair.Second;
                }
            }

            dictionary[tag] = pair;
        }