/// <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;
        }
Beispiel #2
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);
        }
Beispiel #4
0
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         _capacity = 0;
         _handle   = null;
     }
 }
Beispiel #5
0
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         s_handleCache.Release(_handle);
         _capacity = 0;
         _handle   = null;
     }
 }
Beispiel #6
0
 private void Dispose(bool disposing)
 {
     if (_handleCache != null)
     {
         for (int i = 0; i < _handleCache.Length; i++)
         {
             SafeHeapHandle handle = _handleCache[i];
             _handleCache[i] = null;
             if (handle != null && disposing)
             {
                 handle.Dispose();
             }
         }
     }
 }
        /// <summary>
        /// Give a HeapHandle back for potential reuse
        /// </summary>
        public void Release(SafeHeapHandle handle)
        {
            if (handle.ByteLength <= _maxSize)
            {
                for (int i = 0; i < _handleCache.Length; i++)
                {
                    // Push the handles down, walking the last one off the end to keep
                    // the top of the "stack" fresh
                    handle = Interlocked.Exchange(ref _handleCache[i], handle);
                    if (handle == null) return;
                }
            }

            handle.Dispose();
        }
 private void Dispose(bool disposing)
 {
     if (this._handleCache != null)
     {
         for (int i = 0; i < this._handleCache.Length; i++)
         {
             SafeHeapHandle safeHeapHandle = this._handleCache[i];
             this._handleCache[i] = null;
             if (safeHeapHandle != null && disposing)
             {
                 safeHeapHandle.Dispose();
             }
         }
     }
 }
 public void Release(SafeHeapHandle handle)
 {
     if (handle.ByteLength <= this._maxSize)
     {
         for (int i = 0; i < this._handleCache.Length; i++)
         {
             handle = Interlocked.Exchange <SafeHeapHandle>(ref this._handleCache[i], handle);
             if (handle == null)
             {
                 return;
             }
         }
     }
     handle.Dispose();
 }
Beispiel #10
0
        private unsafe void Resize(ulong byteLength)
        {
            if (byteLength == 0)
            {
                ReleaseHandle();
                return;
            }

            if (_handle == null)
            {
                _handle = s_handleCache.Acquire(byteLength);
            }
            else
            {
                _handle.Resize(byteLength);
            }
        }
Beispiel #11
0
        private unsafe void Resize(ulong byteLength)
        {
            if (byteLength == 0)
            {
                ReleaseHandle();
                return;
            }

            if (_handle == null)
            {
                _handle = new SafeHeapHandle(byteLength);
            }
            else
            {
                _handle.Resize(byteLength);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Give a HeapHandle back for potential reuse
        /// </summary>
        public void Release(SafeHeapHandle handle)
        {
            if (handle.ByteLength <= _maxSize)
            {
                for (int i = 0; i < _handleCache.Length; i++)
                {
                    // Push the handles down, walking the last one off the end to keep
                    // the top of the "stack" fresh
                    handle = Interlocked.Exchange(ref _handleCache[i], handle);
                    if (handle == null)
                    {
                        return;
                    }
                }
            }

            handle.Dispose();
        }
Beispiel #13
0
        private unsafe void Resize(ulong byteLength)
        {
            if (byteLength == 0)
            {
                ReleaseHandle();
                return;
            }

            if (_handle == null)
            {
                _handle = s_handleCache.Acquire(byteLength);
            }
            else
            {
                _handle.Resize(byteLength);
            }
        }
Beispiel #14
0
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         s_handleCache.Release(_handle);
         _capacity = 0;
         _handle = null;
     }
 }
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         _capacity = 0;
         _handle = null;
     }
 }
        private unsafe void Resize(ulong byteLength)
        {
            if (byteLength == 0)
            {
                ReleaseHandle();
                return;
            }

            if (_handle == null)
            {
                _handle = new SafeHeapHandle(byteLength);
            }
            else
            {
                _handle.Resize(byteLength);
            }
        }