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

Allocate() public method

Allocates a chunk of memory. If memory is cached it is returned. If no memory is cached then it is allocated. Check the size of the returned buffer to determine how much memory was allocated.
public Allocate ( ) : byte[]
return byte[]
        public byte[] Allocate()
        {
            int offset = this.GetStartingOffset();
            for (int i = 0; i < this.cachedBuffers.Length; ++i)
            {
                int index = (i + offset) % this.cachedBuffers.Length;
                byte[] buffer = Interlocked.Exchange(ref this.cachedBuffers[index], null);
                if (null != buffer)
                {
                    return buffer;
                }
            }

               return new byte[this.bufferSize];
        }

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::Allocate