コード例 #1
0
ファイル: MmfStorage.cs プロジェクト: yongwuhou/NCache
        public MmfObjectPtr Insert(MmfObjectPtr info, byte[] item)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }
            if (info == null)
            {
                throw new ArgumentNullException("item");
            }

            if (!info.View.IsOpen)
            {
                _viewManager.OpenView(info.View);
            }

            // Check if this item can be accomodated in existing space.
            if (info.Arena.HasDataSpace((uint)item.Length))
            {
                info.Arena.SetMemContents(item);
            }
            else
            {
                // Try to add it elsewhere and then delete the current space.
                MmfObjectPtr newInfo = Add(item);
                //if (newInfo != null)
                //{
                //Remove(info);  //as we are updating original hash table links, so before call remove we must update the hash-table entry, instead of updating later.
                //I am moving this remove call to MmfStorageProvide 'Insert' methods ....
                //}
                info = newInfo;
            }

            return(info);
        }
コード例 #2
0
ファイル: MmfStorage.cs プロジェクト: yongwuhou/NCache
        /// <summary>
        /// Gets the object from the memory mapped file.
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public byte[] Get(MmfObjectPtr info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (!info.View.IsOpen)
            {
                _viewManager.OpenView(info.View);
            }

            byte[] item = info.Arena.GetMemContents();
            info.View.Usage++;

            return(item);
        }
コード例 #3
0
ファイル: MmfStorage.cs プロジェクト: yongwuhou/NCache
        public byte[] Remove(MmfObjectPtr info)
        {
            if (info == null)
            {
                throw new ArgumentNullException("info");
            }

            if (!info.View.IsOpen)
            {
                _viewManager.OpenView(info.View);
            }

            byte[] item = info.Arena.GetMemContents();
            // Reclaim space for current item.

            info.View.DeAllocate(info.Arena);

            return(item);
        }