/// <summary> /// Checks if current page is full. If so, writes a pointer to the end of the page and /// returns next available writeable address. /// Otherwise, return current address /// </summary> /// <param name="address"></param> /// <returns></returns> private void WritePointerIfLastObjectOnPage(long address, int objectSize) { long nextPageAddress = PageLocationHelper.GetNextDivisbleNumber(address, Constants.Page_Size); long load = address + (objectSize + Constants.Int64_Byte_Length); bool willBeLastObjectOnPage = load + objectSize >= nextPageAddress - Constants.Int64_Byte_Length; if (willBeLastObjectOnPage) { long nextPagePointer = GetNextUnclaimedDataPage(); using (FileStream fileStream = File.Open(Constants.FILE_NAME, FileMode.Open, FileAccess.Write, FileShare.ReadWrite)) { using (BinaryWriter binaryWriter = new BinaryWriter(fileStream)) { binaryWriter.BaseStream.Position = nextPageAddress - Constants.Int64_Byte_Length; binaryWriter.Write(nextPagePointer); binaryWriter.BaseStream.Position = nextPagePointer; binaryWriter.Write((short)0); } } } }
public long GetPointerToNextPage(long pageAddress) { long pointerToNextPage = PageLocationHelper.GetNextDivisbleNumber(pageAddress, Constants.Page_Size) - Constants.Int64_Byte_Length; using (FileStream fs = new FileStream(Constants.FILE_NAME, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BinaryReader binaryReader = new BinaryReader(fs)) { binaryReader.BaseStream.Position = pointerToNextPage; long nextPageAddress = binaryReader.ReadInt64(); return(nextPageAddress); } } }