Microsoft.Isam.Esent.Interop.MemoryCache.Free C# (CSharp) Method

Free() public method

Frees an unused buffer. This may be added to the cache.
public Free ( byte data ) : void
data byte The memory to free.
return void
        public void Free(byte[] data)
        {
            if (null == data)
            {
                throw new ArgumentNullException("data");
            }

            if (data.Length != this.bufferSize)
            {
                throw new ArgumentOutOfRangeException("data", data.Length, "buffer is not correct size for this MemoryCache");
            }

            int offset = this.GetStartingOffset();

            // The buffers are garbage collected so we don't need to make Free()
            // completely safe. In a multi-threaded situation we may see a null
            // slot and then overwrite a buffer which was just freed into the slot.
            // That will cause us to lose a buffer which could have been placed
            // in a different slot, but in return we can do the Free() without
            // expensive interlocked operations.
            for (int i = 0; i < this.cachedBuffers.Length; ++i)
            {
                int index = (i + offset) % this.cachedBuffers.Length;
                if (null == this.cachedBuffers[index])
                {
                    this.cachedBuffers[index] = data;
                    break;
                }
            }
        }

Usage Example

Esempio n. 1
0
        /// <summary>
        /// Update the tableid and position the tableid on the record that was modified.
        /// This can be useful when inserting a record because by default the tableid
        /// remains in its old location.
        /// </summary>
        /// <remarks>
        /// Save is the final step in performing an insert or an update. The update is begun by
        /// calling creating an Update object and then by calling JetSetColumn or JetSetColumns one or more times
        /// to set the record state. Finally, Update is called to complete the update operation.
        /// Indexes are updated only by Update or and not during JetSetColumn or JetSetColumns
        /// </remarks>
        public void SaveAndGotoBookmark()
        {
            var bookmark = bookmarkCache.Allocate();
            int actualBookmarkSize;

            this.Save(bookmark, bookmark.Length, out actualBookmarkSize);
            Api.JetGotoBookmark(this.sesid, this.tableid, bookmark, actualBookmarkSize);
            bookmarkCache.Free(bookmark);
        }
All Usage Examples Of Microsoft.Isam.Esent.Interop.MemoryCache::Free