Пример #1
0
        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);
            }
        }
Пример #2
0
        /// <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...
            }
        }
Пример #3
0
        /// <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));
            }
        }
Пример #4
0
 private void Dispose(bool disposing)
 {
     if (disposing)
     {
         fixedAreaBlock = null;
         areaMap        = null;
     }
 }
Пример #5
0
        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;
        }
Пример #6
0
        /// <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);
            }
        }
Пример #7
0
        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;
        }
Пример #8
0
 private void Dispose(bool disposing)
 {
     if (disposing) {
         fixedAreaBlock = null;
         areaMap = null;
     }
 }