public DataFile(string filePath, long initialSize, int growthIncrement) { try { bool isNew = !File.Exists(filePath); memoryMapper = new MemoryMapper(filePath, initialSize); mapping = MemoryMapping.Create(memoryMapper.fs, Constants.AllocationGranularity); dataFileHeaderPointer = (DataFileHeader *)mapping.GetBaseAddress(); this.growthIncrement = (growthIncrement + Constants.AllocationGranularityMask) / Constants.AllocationGranularity * Constants.AllocationGranularity; if (isNew) { InitializeHeader(); } else { ValidateHeader(); } } catch { Dispose(); throw; } }
internal void AddMapping(MemoryMapping mapping) { try { } // prevent ThreadAbortException from corrupting mappings collection finally { mappings.Add(mapping); mapping.AddRef(); baseAddress = mapping.GetBaseAddress(); BaseAddressChanged?.Invoke(this, new BaseAddressChangedEventArgs(baseAddress)); } }
public byte *Grow(long bytesToGrow) { CheckDisposed(); lock (SyncObject) { CheckDisposed(); var newMapping = MemoryMapping.Grow(bytesToGrow, mapping); if (mapping != newMapping) { var oldMapping = mapping; mapping = newMapping; oldMapping.Release(); foreach (var session in sessions) { session.AddMapping(newMapping); } } return(mapping.GetBaseAddress()); } }