private InMemoryBlock GetAreaBlock(long pointer) { lock (this) { // Find the pointer in the hash var hashPos = (int)(pointer % areaMap.Length); InMemoryBlock prev = null; var block = areaMap[hashPos]; // Search for this pointer while (block != null && block.Id != pointer) { prev = block; block = block.Next; } if (block == null) { throw new IOException("Pointer " + pointer + " is invalid."); } // Move the element to the start of the list. if (prev != null) { prev.Next = block.Next; block.Next = areaMap[hashPos]; areaMap[hashPos] = block; } return(block); } }
/// <inheritdoc/> public void DeleteArea(long id) { lock (this) { // Find the pointer in the hash var hashPos = (int)(id % areaMap.Length); InMemoryBlock prev = null; InMemoryBlock block = areaMap[hashPos]; // Search for this pointer while (block != null && block.Id != id) { prev = block; block = block.Next; } // If not found if (block == null) { throw new IOException("Area ID " + id + " is invalid."); } // Remove if (prev == null) { areaMap[hashPos] = block.Next; } else { prev.Next = block.Next; } // Garbage collector should do the rest... } }
/// <inheritdoc/> public IArea CreateArea(long size) { if (size > Int32.MaxValue) { throw new IOException("'size' is too large."); } lock (this) { // Generate a unique id for this area. long id = uniqueIdKey; ++uniqueIdKey; // Create the element. var element = new InMemoryBlock(id, (int)size); // The position in the hash map int hashPos = (int)(id % areaMap.Length); // Add to the chain element.Next = areaMap[hashPos]; areaMap[hashPos] = element; return(element.GetArea(false)); } }
private void Dispose(bool disposing) { if (disposing) { fixedAreaBlock = null; areaMap = null; } }
private void Dispose(bool disposing) { if (disposing) { if (areaMap != null) { for (int i = 0; i < areaMap.Length; i++) { var block = areaMap[i]; if (block != null) { block.Dispose(); } areaMap[i] = null; } } } fixedAreaBlock = null; areaMap = null; }
/// <inheritdoc/> public IArea CreateArea(long size) { if (size > Int32.MaxValue) throw new IOException("'size' is too large."); lock (this) { // Generate a unique id for this area. long id = uniqueIdKey; ++uniqueIdKey; // Create the element. var element = new InMemoryBlock(id, (int)size); // The position in the hash map int hashPos = (int)(id % areaMap.Length); // Add to the chain element.Next = areaMap[hashPos]; areaMap[hashPos] = element; return element.GetArea(false); } }
private void Dispose(bool disposing) { if (disposing) { if (areaMap != null) { for (int i = 0; i < areaMap.Length; i++) { var block = areaMap[i]; if (block != null) block.Dispose(); areaMap[i] = null; } } } fixedAreaBlock = null; areaMap = null; }