public override void AllocateMorePages(Transaction tx, long newLength) { if (newLength <= _allocatedSize) { throw new ArgumentException("Cannot set the legnth to less than the current length"); } var oldSize = _allocatedSize; _allocatedSize = newLength; NumberOfAllocatedPages = _allocatedSize / PageSize; var newPtr = Marshal.AllocHGlobal(new IntPtr(_allocatedSize)); var newBase = (byte *)newPtr.ToPointer(); NativeMethods.memcpy(newBase, _base, new IntPtr(oldSize)); _base = newBase; _ptr = newPtr; var oldPager = PagerState; var newPager = new PagerState { Ptr = newPtr }; newPager.AddRef(); // one for the pager if (tx != null) // we only pass null during startup, and we don't need it there { newPager.AddRef(); // one for the current transaction tx.AddPagerState(PagerState); } PagerState = newPager; oldPager.Release(); }
public override void AllocateMorePages(Transaction tx, long newLength) { if (newLength < _fileStream.Length) { throw new ArgumentException("Cannot set the legnth to less than the current length"); } if (newLength == _fileStream.Length) { return; } // need to allocate memory again _fileStream.SetLength(newLength); PagerState.Release(); // when the last transaction using this is over, will dispose it PagerState newPager = CreateNewPagerState(); if (tx != null) // we only pass null during startup, and we don't need it there { newPager.AddRef(); // one for the current transaction tx.AddPagerState(newPager); } PagerState = newPager; NumberOfAllocatedPages = newPager.Accessor.Capacity / PageSize; }
internal void EnsurePagerStateReference(PagerState state) { if (_pagerStates.Add(state)) { state.AddRef(); } }
protected AbstractPager() { MaxNodeSize = (PageSize - Constants.PageHeaderSize) / Constants.MinKeysInPage; PageMaxSpace = PageSize - Constants.PageHeaderSize; PageMinSpace = (int)(PageMaxSpace * 0.33); PagerState = new PagerState(); _tempPage = Marshal.AllocHGlobal(PageSize); PagerState.AddRef(); }
public PureMemoryPager() { _ptr = Marshal.AllocHGlobal(MinIncreaseSize); _base = (byte *)_ptr.ToPointer(); NumberOfAllocatedPages = _allocatedSize / PageSize; PagerState.Release(); PagerState = new PagerState { Ptr = _ptr }; PagerState.AddRef(); }
internal void EnsurePagerStateReference(PagerState state) { if (state == _lastState || state == null) { return; } if (_pagerStates.Add(state)) { state.AddRef(); _lastState = state; } }
public void EnsurePagerStateReference(PagerState state) { if (state == _lastState || state == null) { return; } _lastState = state; if (_pagerStates.Add(state) == false) { return; } state.AddRef(); }
private PagerState CreateNewPagerState() { var mmf = MemoryMappedFile.CreateFromFile(_fileStream, Guid.NewGuid().ToString(), _fileStream.Length, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.None, true); var accessor = mmf.CreateViewAccessor(); byte* p = null; accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref p); var newPager = new PagerState { Accessor = accessor, File = mmf, Base = p }; newPager.AddRef(); // one for the pager return newPager; }
private PagerState CreateNewPagerState() { var mmf = MemoryMappedFile.CreateFromFile(_fileStream, Guid.NewGuid().ToString(), _fileStream.Length, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.None, true); var accessor = mmf.CreateViewAccessor(); byte *p = null; accessor.SafeMemoryMappedViewHandle.AcquirePointer(ref p); var newPager = new PagerState { Accessor = accessor, File = mmf, Base = p }; newPager.AddRef(); // one for the pager return(newPager); }
private PagerState CreatePagerState() { var mmf = MemoryMappedFile.CreateFromFile(_fileStream, null, _fileStream.Length, _memoryMappedFileAccess, null, HandleInheritability.None, true); var fileMappingHandle = mmf.SafeMemoryMappedFileHandle.DangerousGetHandle(); var mmFileAccessType = _access == Win32NativeFileAccess.GenericRead ? Win32MemoryMapNativeMethods.NativeFileMapAccessType.Read : Win32MemoryMapNativeMethods.NativeFileMapAccessType.Read | Win32MemoryMapNativeMethods.NativeFileMapAccessType.Write; var startingBaseAddressPtr = Win32MemoryMapNativeMethods.MapViewOfFileEx(fileMappingHandle, mmFileAccessType, 0, 0, UIntPtr.Zero, //map all what was "reserved" in CreateFileMapping on previous row null); if (startingBaseAddressPtr == (byte*)0) //system didn't succeed in mapping the address where we wanted throw new Win32Exception(); var allocationInfo = new PagerState.AllocationInfo { BaseAddress = startingBaseAddressPtr, Size = _fileStream.Length, MappedFile = mmf }; var newPager = new PagerState(this) { Files = new[] { mmf }, MapBase = startingBaseAddressPtr, AllocationInfos = new[] { allocationInfo } }; newPager.AddRef(); // one for the pager return newPager; }
private PagerState CreatePagerState() { var startingBaseAddressPtr = Syscall.mmap(IntPtr.Zero, (ulong)_totalAllocationSize, MmapProts.PROT_READ | MmapProts.PROT_WRITE, MmapFlags.MAP_SHARED, _fd, 0); if (startingBaseAddressPtr.ToInt64() == -1) //system didn't succeed in mapping the address where we wanted PosixHelper.ThrowLastError(Marshal.GetLastWin32Error()); var allocationInfo = new PagerState.AllocationInfo { BaseAddress = (byte*)startingBaseAddressPtr.ToPointer(), Size = _totalAllocationSize, MappedFile = null }; var newPager = new PagerState(this) { Files = null, // unused MapBase = allocationInfo.BaseAddress, AllocationInfos = new[] { allocationInfo } }; newPager.AddRef(); // one for the pager return newPager; }
private PagerState CreateInitialPagerState(long size) { var allocationSize = NearestSizeToAllocationGranularity(size); var mmf = MemoryMappedFile.CreateNew(null, allocationSize, MemoryMappedFileAccess.ReadWrite); var fileMappingHandle = mmf.SafeMemoryMappedFileHandle.DangerousGetHandle(); var startingBaseAddressPtr = Win32MemoryMapNativeMethods.MapViewOfFileEx(fileMappingHandle, Win32MemoryMapNativeMethods.NativeFileMapAccessType.Read | Win32MemoryMapNativeMethods.NativeFileMapAccessType.Write, 0, 0, UIntPtr.Zero, //map all what was "reserved" in CreateFileMapping on previous row null); if (startingBaseAddressPtr == (byte*)0) //system didn't succeed in mapping the address where we wanted throw new Win32Exception(); var allocationInfo = new PagerState.AllocationInfo { BaseAddress = startingBaseAddressPtr, Size = allocationSize, MappedFile = mmf }; var newPager = new PagerState(this) { Files = new[] { mmf }, MapBase = startingBaseAddressPtr, AllocationInfos = new[] { allocationInfo } }; newPager.AddRef(); return newPager; }
internal void EnsurePagerStateReference(PagerState state) { if (_pagerStates.Add(state)) state.AddRef(); }