/* Copyright (C) 2014 DaikonForge */
namespace DaikonForge.VoIP
{
using System.Collections.Generic;
///
/// Helper class for working with pooled arrays
///
public class TempArray
{
private static Dictionary> pool = new Dictionary>();
///
/// Obtain an array of the given length
///
public static T[] Obtain( int length )
{
Queue pool = getPool( length );
if( pool.Count > 0 )
{
return pool.Dequeue();
}
return new T[ length ];
}
///
/// Release an array back to the pool
///
public static void Release( T[] array )
{
pool[ array.Length ].Enqueue( array );
}
private static Queue getPool( int length )
{
if( !pool.ContainsKey( length ) )
{
pool[ length ] = new Queue();
}
return pool[ length ];
}
}
}