1
Fork 0
mirror of https://github.com/Steffo99/better-tee.git synced 2024-11-25 16:34:17 +00:00
better-tee/Assets/Packages/Mirror/Runtime/NetworkWriterPool.cs

28 lines
648 B
C#
Raw Normal View History

2019-09-17 15:43:32 +00:00
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);
}
}
}