private CachingBin.Page SyncReadPage(long startAddress)
 {
     CachingBin.Page page = new CachingBin.Page(_pageSize);
     LoadPage(page, startAddress);
     page.EnsureEndAddress(_fileLength);
     return(page);
 }
 private CachingBin.Page GetPage(long startAddress, IFunction4 producer)
 {
     CachingBin.Page page = ((CachingBin.Page)_cache.Produce(PageAddressFor(startAddress
                                                                            ), producer, _onDiscardPage));
     page.EnsureEndAddress(_fileLength);
     return(page);
 }
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 private void FlushPage(CachingBin.Page page)
 {
     if (!page._dirty)
     {
         return;
     }
     WritePageToDisk(page);
 }
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 protected virtual void FlushAllPages()
 {
     for (IEnumerator pIter = _cache.GetEnumerator(); pIter.MoveNext();)
     {
         CachingBin.Page p = ((CachingBin.Page)pIter.Current);
         FlushPage(p);
     }
 }
 public object Apply(object pageAddress)
 {
     // in case that page is not found in the cache
     CachingBin.Page newPage = ((CachingBin.Page) this._enclosing._pagePool.BorrowObject
                                    ());
     this._enclosing.ResetPageAddress(newPage, ((long)pageAddress));
     return(newPage);
 }
Beispiel #6
0
		private CachingBin.Page[] NewPagePool(int pageCount)
		{
			CachingBin.Page[] pages = new CachingBin.Page[pageCount];
			for (int i = 0; i < pages.Length; ++i)
			{
				pages[i] = new CachingBin.Page(_pageSize);
			}
			return pages;
		}
 private CachingBin.Page[] NewPagePool(int pageCount)
 {
     CachingBin.Page[] pages = new CachingBin.Page[pageCount];
     for (int i = 0; i < pages.Length; ++i)
     {
         pages[i] = new CachingBin.Page(_pageSize);
     }
     return(pages);
 }
Beispiel #8
0
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		private void LoadPage(CachingBin.Page page, long pos)
		{
			long startAddress = pos - pos % _pageSize;
			page._startAddress = startAddress;
			int count = _bin.Read(page._startAddress, page._buffer, page._bufferSize);
			if (count > 0)
			{
				page._endAddress = startAddress + count;
			}
			else
			{
				page._endAddress = startAddress;
			}
		}
Beispiel #9
0
		/// <summary>Writes the buffer to cache using pages</summary>
		/// <param name="pos">start position to write</param>
		/// <param name="buffer">source buffer</param>
		/// <param name="length">how many bytes to write</param>
		/// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
		public override void Write(long pos, byte[] buffer, int length)
		{
			long startAddress = pos;
			int bytesToWrite = length;
			int bufferOffset = 0;
			while (bytesToWrite > 0)
			{
				// page doesn't need to loadFromDisk if the whole page is dirty
				bool loadFromDisk = (bytesToWrite < _pageSize) || (startAddress % _pageSize != 0);
				CachingBin.Page page = GetPage(startAddress, loadFromDisk);
				int writtenBytes = page.Write(buffer, bufferOffset, startAddress, bytesToWrite);
				bytesToWrite -= writtenBytes;
				startAddress += writtenBytes;
				bufferOffset += writtenBytes;
			}
			long endAddress = startAddress;
			_fileLength = Math.Max(endAddress, _fileLength);
		}
Beispiel #10
0
		private int ReadInternal(long pos, byte[] buffer, int length, bool syncRead)
		{
			long startAddress = pos;
			int bytesToRead = length;
			int totalRead = 0;
			while (bytesToRead > 0)
			{
				CachingBin.Page page = syncRead ? SyncReadPage(startAddress) : GetPage(startAddress
					, _producerFromDisk);
				int readBytes = page.Read(buffer, totalRead, startAddress, bytesToRead);
				if (readBytes <= 0)
				{
					break;
				}
				bytesToRead -= readBytes;
				startAddress += readBytes;
				totalRead += readBytes;
			}
			return totalRead == 0 ? -1 : totalRead;
		}
Beispiel #11
0
		private CachingBin.Page SyncReadPage(long startAddress)
		{
			CachingBin.Page page = new CachingBin.Page(_pageSize);
			LoadPage(page, startAddress);
			page.EnsureEndAddress(_fileLength);
			return page;
		}
Beispiel #12
0
 /// <exception cref="Db4objects.Db4o.Ext.Db4oIOException"></exception>
 private void WritePageToDisk(CachingBin.Page page)
 {
     base.Write(page._startAddress, page._buffer, page.Size());
     page._dirty = false;
 }
Beispiel #13
0
 private void ResetPageAddress(CachingBin.Page page, long startAddress)
 {
     page._startAddress = startAddress;
     page._endAddress   = startAddress + _pageSize;
 }