コード例 #1
0
            public MemoryMappedPage GetPage(int blockId)
            {
                if (blockId < 0)
                {
                    throw new ArgumentOutOfRangeException("blockId");
                }

                int pageIndex = blockId / this.BlocksPerPage;
                int index     = 0;

                lock (_pages)
                {
                    //在页面队列中查找指定页面号的页面对象,如果找到则直接返回
                    for (; index < _pages.Length; index++)
                    {
                        if (_pages[index] == null)
                        {
                            break;
                        }

                        if (pageIndex == _pages[index].PageIndex)
                        {
                            return(_pages[index]);
                        }
                    }

                    //获取即将要彻底销毁的页面对象
                    var page = _pages[Math.Min(index, _pages.Length - 1)];

                    //如果即将要销毁的页面对象不为空则彻底销毁它
                    if (page != null)
                    {
                        page.Kill();
                    }

                    //以下循环移动待页面队列,以腾出位置给新页面对象
                    for (int i = Math.Min(index, _pages.Length - 1); i > 0; i--)
                    {
                        _pages[i] = _pages[i - 1];
                    }

                    return(_pages[0] = new MemoryMappedPage(this, pageIndex, _bufferManager.Storage.CreateViewStream(_storagePosition + (pageIndex * PageSize), PageSize)));
                }
            }
コード例 #2
0
			public MemoryMappedPage GetPage(int blockId)
			{
				if(blockId < 0)
					throw new ArgumentOutOfRangeException("blockId");

				int pageIndex = blockId / this.BlocksPerPage;
				int index = 0;

				lock(_pages)
				{
					//在页面队列中查找指定页面号的页面对象,如果找到则直接返回
					for(; index < _pages.Length; index++)
					{
						if(_pages[index] == null)
							break;

						if(pageIndex == _pages[index].PageIndex)
							return _pages[index];
					}

					//获取即将要彻底销毁的页面对象
					var page = _pages[Math.Min(index, _pages.Length - 1)];

					//如果即将要销毁的页面对象不为空则彻底销毁它
					if(page != null)
						page.Kill();

					//以下循环移动待页面队列,以腾出位置给新页面对象
					for(int i = Math.Min(index, _pages.Length - 1); i > 0; i--)
					{
						_pages[i] = _pages[i - 1];
					}

					return _pages[0] = new MemoryMappedPage(this, pageIndex, _bufferManager.Storage.CreateViewStream(_storagePosition + (pageIndex * PageSize), PageSize));
				}
			}