Ejemplo n.º 1
0
 public void GrabHandleFromEmptyCache()
 {
     using (SafeHeapHandleCache cache = new SafeHeapHandleCache(minSize: 5, maxSize: 100, maxHandles: 2))
     {
         var handle = cache.Acquire();
         Assert.NotNull(handle);
         Assert.Equal((ulong)5, handle.ByteLength);
     }
 }
Ejemplo n.º 2
0
 public void LatestPopped()
 {
     using (SafeHeapHandleCache cache = new SafeHeapHandleCache(minSize: 5, maxSize: 100, maxHandles: 2))
     {
         var first = cache.Acquire();
         var second = cache.Acquire();
         cache.Release(first);
         cache.Release(second);
         Assert.Same(second, cache.Acquire());
         Assert.Same(first, cache.Acquire());
     }
 }
Ejemplo n.º 3
0
        public void CachedCountTest(int maxCount, int itemsToCache, int expected)
        {
            using (SafeHeapHandleCache cache = new SafeHeapHandleCache(minSize: 5, maxSize: 100, maxHandles: maxCount))
            {
                for (int i = 0; i < itemsToCache; i++)
                {
                    cache.Release(new SafeHeapHandle(10));
                }

                int count = cache._handleCache.Count(h => h != null);
                Assert.Equal(expected, count);
            }
        }
Ejemplo n.º 4
0
 public void OldestPushedOff()
 {
     using (SafeHeapHandleCache cache = new SafeHeapHandleCache(minSize: 5, maxSize: 100, maxHandles: 2))
     {
         var first = cache.Acquire();
         var second = cache.Acquire();
         var third = cache.Acquire();
         cache.Release(first);
         cache.Release(second);
         cache.Release(third);
         Assert.True(first.IsClosed);
         Assert.False(second.IsClosed);
         Assert.False(third.IsClosed);
     }
 }
Ejemplo n.º 5
0
 static NativeBuffer()
 {
     s_emptyHandle = new EmptySafeHandle();
     s_handleCache = new SafeHeapHandleCache();
 }