Пример #1
0
        protected void UnsafeCache(T value)
        {
            int offs   = ElementSize * Count;
            var handle = GCHandle.Alloc(backing, GCHandleType.Pinned);

            try
            {
                var ptr = handle.AddrOfPinnedObject() + offs;
                Marshal.StructureToPtr(value, ptr, false);
                Count += 1;
                OnCache?.Invoke(value);
                decache_reset.Set();
            }
            finally
            {
                handle.Free();
            }
        }
Пример #2
0
        private int Calculate(int allCount, int chosenCount)
        {
            if (chosenCount == 0 || allCount == chosenCount)
            {
                return(1);
            }

            var savedValue = _cache[allCount, chosenCount];

            if (savedValue > -1)
            {
                OnCache?.Invoke(allCount, chosenCount);
                return(savedValue);
            }

            OnCall?.Invoke(allCount, chosenCount);
            return(_cache[allCount, chosenCount] = Calculate(allCount - 1, chosenCount) + Calculate(allCount - 1, chosenCount - 1));
        }