private void CloseMapFile() { if (Mmf == null) { Trace.TraceWarning("Mmf is null in CloseMapFile"); return; } Mmf.Dispose(); Mmf = null; }
/// <summary> /// Grow the array to support more data /// </summary> /// <param name="requiredMinCapacity">The size to grow from</param> public void EnsureCapacity(long requiredMinCapacity) { Trace.Assert(requiredMinCapacity > 0); // catch int overflow if there is more than one fixed in Backing constructor if (Capacity >= requiredMinCapacity) { return; } FileMutex.WaitOne(); try { switch (PersistenceMode) { case PersistenceMode.Persist: case PersistenceMode.TemporaryPersist: var oldSize = Capacity; var newCapacity = (long)(oldSize * ((100F + _GROW_PERCENTAGE) / 100F)); Capacity = newCapacity < requiredMinCapacity ? requiredMinCapacity : newCapacity; CloseMapFile(); Trace.Assert(Mmf == null); Mmf = CreateOrOpenFile(_fileName, Capacity, PersistenceMode, FileMutex, true); // recreate views so that unsafe r/w on already created wrap do not throw foreach (var viewWrap in _vw.Values) { viewWrap._va.Dispose(); viewWrap._va = Mmf.CreateViewAccessor(); } break; case PersistenceMode.Ephemeral: throw new NotSupportedException("In-memory MMFs do not support resizing. Set initial capacity large enough, only actually used memory will be consumed from RAM"); default: throw new ArgumentOutOfRangeException(); } } finally { FileMutex.ReleaseMutex(); } }