Beispiel #1
0
        /// <summary>
        /// Get a HeapHandle
        /// </summary>
        public SafeHeapHandle Acquire(ulong minSize = 0)
        {
            if (minSize < _minSize)
            {
                minSize = _minSize;
            }

            SafeHeapHandle handle = null;

            for (int i = 0; i < _handleCache.Length; i++)
            {
                handle = Interlocked.Exchange(ref _handleCache[i], null);
                if (handle != null)
                {
                    break;
                }
            }

            if (handle != null)
            {
                // One possible future consideration is to attempt cycling through to
                // find one that might already have sufficient capacity
                if (handle.ByteLength < minSize)
                {
                    handle.Resize(minSize);
                }
            }
            else
            {
                handle = new SafeHeapHandle(minSize);
            }

            return(handle);
        }
        public SafeHeapHandle Acquire(ulong minSize = 0UL)
        {
            if (minSize < this._minSize)
            {
                minSize = this._minSize;
            }
            SafeHeapHandle safeHeapHandle = null;

            for (int i = 0; i < this._handleCache.Length; i++)
            {
                safeHeapHandle = Interlocked.Exchange <SafeHeapHandle>(ref this._handleCache[i], null);
                if (safeHeapHandle != null)
                {
                    break;
                }
            }
            if (safeHeapHandle != null)
            {
                if (safeHeapHandle.ByteLength < minSize)
                {
                    safeHeapHandle.Resize(minSize);
                }
            }
            else
            {
                safeHeapHandle = new SafeHeapHandle(minSize);
            }
            return(safeHeapHandle);
        }