日期:2014-05-18  浏览次数:20890 次

请各位大侠帮我解释一下:SocketAsyncEventArgsPool
菜鸟我刚刚开始学些网络这方面的,在msdn中看到SocketAsyncEventArgs例子中的SocketAsyncEventArgsPool 不太明白这个对象是什么意思,也没有找到在哪定义了这个类,求各位大侠帮忙解释一下。 
非常感谢!

------解决方案--------------------
看SocketAsyncEventArgs 构造函数的帮助,代码如下
C# code


// Represents a collection of reusable SocketAsyncEventArgs objects.  
class SocketAsyncEventArgsPool
{
    Stack<SocketAsyncEventArgs> m_pool;

    // Initializes the object pool to the specified size
    //
    // The "capacity" parameter is the maximum number of 
    // SocketAsyncEventArgs objects the pool can hold
    public SocketAsyncEventArgsPool(int capacity)
    {
        m_pool = new Stack<SocketAsyncEventArgs>(capacity);
    }

    // Add a SocketAsyncEventArg instance to the pool
    //
    //The "item" parameter is the SocketAsyncEventArgs instance 
    // to add to the pool
    public void Push(SocketAsyncEventArgs item)
    {
        if (item == null) { throw new ArgumentNullException("Items added to a SocketAsyncEventArgsPool cannot be null"); }
        lock (m_pool)
        {
            m_pool.Push(item);
        }
    }

    // Removes a SocketAsyncEventArgs instance from the pool
    // and returns the object removed from the pool
    public SocketAsyncEventArgs Pop()
    {
        lock (m_pool)
        {
            return m_pool.Pop();
        }
    }

    // The number of SocketAsyncEventArgs instances in the pool
    public int Count
    {
        get { return m_pool.Count; }
    }

}

------解决方案--------------------
是的,这个类是自己写的。