Exemplo n.º 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;
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         _capacity = 0;
         _handle   = null;
     }
 }
Exemplo n.º 5
0
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         s_handleCache.Release(_handle);
         _capacity = 0;
         _handle   = null;
     }
 }
Exemplo n.º 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();
             }
         }
     }
 }
Exemplo n.º 7
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();
        }
 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();
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 11
0
        private unsafe void Resize(ulong byteLength)
        {
            if (byteLength == 0)
            {
                ReleaseHandle();
                return;
            }

            if (_handle == null)
            {
                _handle = new SafeHeapHandle(byteLength);
            }
            else
            {
                _handle.Resize(byteLength);
            }
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 14
0
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         s_handleCache.Release(_handle);
         _capacity = 0;
         _handle = null;
     }
 }
Exemplo n.º 15
0
 private void ReleaseHandle()
 {
     if (_handle != null)
     {
         _capacity = 0;
         _handle = null;
     }
 }
Exemplo n.º 16
0
        private unsafe void Resize(ulong byteLength)
        {
            if (byteLength == 0)
            {
                ReleaseHandle();
                return;
            }

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