1
Fork 0
mirror of https://github.com/Steffo99/better-tee.git synced 2024-11-22 23:34:18 +00:00
better-tee/Assets/Packages/Mirror/Runtime/NetworkWriterPool.cs
2019-09-17 17:43:32 +02:00

28 lines
No EOL
648 B
C#

using System.Collections.Generic;
namespace Mirror
{
public static class NetworkWriterPool
{
static readonly Stack<NetworkWriter> pool = new Stack<NetworkWriter>();
public static NetworkWriter GetWriter()
{
if (pool.Count != 0)
{
NetworkWriter writer = pool.Pop();
// reset cached writer length and position
writer.SetLength(0);
return writer;
}
return new NetworkWriter();
}
public static void Recycle(NetworkWriter writer)
{
pool.Push(writer);
}
}
}