Pool.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Pool.cs / 1305376 / Pool.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
namespace System.IdentityModel
{ 
    // see SynchronizedPool for a threadsafe implementation
    class Pool where T : class 
    { 
        T[] items;
        int count; 

        public Pool(int maxCount)
        {
            items = new T[maxCount]; 
        }
 
        public int Count 
        {
            get { return count; } 
        }

        public T Take()
        { 
            if (count > 0)
            { 
                T item = items[--count]; 
                items[count] = null;
                return item; 
            }
            else
            {
                return null; 
            }
        } 
 
        public bool Return(T item)
        { 
            if (count < items.Length)
            {
                items[count++] = item;
                return true; 
            }
            else 
            { 
                return false;
            } 
        }

        public void Clear()
        { 
            for (int i = 0; i < count; i++)
                items[i] = null; 
            count = 0; 
        }
    } 
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.


                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK