public MemoryMapper(string filePath, long initialFileSize) { try { if (initialFileSize <= 0 || initialFileSize % Constants.AllocationGranularity != 0) { throw new ArgumentException("The initial file size must be a multiple of 64Kb and grater than zero"); } bool existingFile = File.Exists(filePath); fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); if (existingFile) { if (fs.Length <= 0 || fs.Length % Constants.AllocationGranularity != 0) { throw new ArgumentException("Invalid file. Its lenght must be a multiple of 64Kb and greater than zero"); } } else { fs.SetLength(initialFileSize); } mapping = MemoryMapping.Create(fs); } catch { Dispose(); throw; } }
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; } }