Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
protobuf-net object pooling
internal partial class BroadcastAvailable
{
static Pool<BroadcastAvailable> s_Pool = new Pool<BroadcastAvailable> (Behave.Runtime.Debugger.kFrameQueueSize, p => new BroadcastAvailable ());
static BroadcastAvailable ()
{
RuntimeTypeModel.Default[typeof (BroadcastAvailable)].SetFactory ("Get");
}
public static BroadcastAvailable Get ()
{
return s_Pool.Spawn ();
}
public static void Recycle (BroadcastAvailable broadcastAvailable)
{
if (broadcastAvailable == null)
{
return;
}
broadcastAvailable.IP = null;
broadcastAvailable.Port = 0;
broadcastAvailable.Ticks = 0;
broadcastAvailable.Version = 0;
broadcastAvailable.Name = "";
s_Pool.Despawn (broadcastAvailable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment