Exemplo n.º 1
0
 public void OnMessage(bool binary, IntPtr data, int size)
 {
     if (binary)
     {
         var msg = pool.Rent(size);
         Marshal.Copy(data, msg.bytes, msg.start, size);
         received.Enqueue(msg);
     }
     else
     {
         Debug.LogException(new NotImplementedException());
     }
 }
        public void CheckReturnToPoolAndRent()
        {
            try
            {
                var dummyMessage = new Message("Message for testing");
                Assert.IsFalse(dummyMessage.IsMessagePooled);

                dummyMessage.ReturnToPool();
                Assert.IsTrue(dummyMessage.IsMessagePooled);

                var dummyMessage2 = MessagePool.Rent(10);
                Assert.IsFalse(dummyMessage2.IsMessagePooled);
            }
            finally
            {
                // Cleanup
                MessagePool.Clear();
            }
        }