コード例 #1
0
        // do nothing
        public override void Free(Slot slot)
        {
            int address = slot.Address();

            if (address <= 0)
            {
                throw new ArgumentException();
            }
            int length = slot.Length();

            if (DTrace.enabled)
            {
                DTrace.FreespacemanagerRamFree.LogLength(address, length);
            }
            _finder._key = address;
            FreeSlotNode sizeNode;
            FreeSlotNode addressnode = (FreeSlotNode)Tree.FindSmaller(_freeByAddress, _finder
                                                                      );

            if ((addressnode != null) && ((addressnode._key + addressnode._peer._key) == address
                                          ))
            {
                sizeNode = addressnode._peer;
                RemoveFromFreeBySize(sizeNode);
                sizeNode._key += length;
                FreeSlotNode secondAddressNode = (FreeSlotNode)Tree.FindGreaterOrEqual(_freeByAddress
                                                                                       , _finder);
                if ((secondAddressNode != null) && (address + length == secondAddressNode._key))
                {
                    sizeNode._key += secondAddressNode._peer._key;
                    RemoveFromBothTrees(secondAddressNode._peer);
                }
                sizeNode.RemoveChildren();
                AddToFreeBySize(sizeNode);
            }
            else
            {
                addressnode = (FreeSlotNode)Tree.FindGreaterOrEqual(_freeByAddress, _finder);
                if ((addressnode != null) && (address + length == addressnode._key))
                {
                    sizeNode = addressnode._peer;
                    RemoveFromBothTrees(sizeNode);
                    sizeNode._key   += length;
                    addressnode._key = address;
                    addressnode.RemoveChildren();
                    sizeNode.RemoveChildren();
                    _freeByAddress = Tree.Add(_freeByAddress, addressnode);
                    AddToFreeBySize(sizeNode);
                }
                else
                {
                    if (CanDiscard(length))
                    {
                        return;
                    }
                    AddFreeSlotNodes(address, length);
                }
            }
            SlotFreed(slot);
        }
コード例 #2
0
        // Do nothing.
        // The RAM manager frees itself on reading.
        public override Slot AllocateSlot(int length)
        {
            _finder._key    = length;
            _finder._object = null;
            _freeBySize     = FreeSlotNode.RemoveGreaterOrEqual((FreeSlotNode)_freeBySize, _finder
                                                                );
            if (_finder._object == null)
            {
                return(null);
            }
            FreeSlotNode node = (FreeSlotNode)_finder._object;

            _listener.SlotRemoved(node._key);
            int blocksFound = node._key;
            int address     = node._peer._key;

            _freeByAddress = _freeByAddress.RemoveNode(node._peer);
            int remainingBlocks = blocksFound - length;

            if (SplitRemainder(remainingBlocks))
            {
                AddFreeSlotNodes(address + length, remainingBlocks);
            }
            else
            {
                length = blocksFound;
            }
            if (DTrace.enabled)
            {
                DTrace.FreespacemanagerGetSlot.LogLength(address, length);
            }
            return(new Slot(address, length));
        }
コード例 #3
0
		private void AddFreeSlotNodes(int address, int length)
		{
			FreeSlotNode addressNode = new FreeSlotNode(address);
			addressNode.CreatePeer(length);
			_freeByAddress = Tree.Add(_freeByAddress, addressNode);
			AddToFreeBySize(addressNode._peer);
		}
コード例 #4
0
ファイル: FreeSlotNode.cs プロジェクト: masroore/db4o
 public override object ShallowClone()
 {
     var frslot = new FreeSlotNode
         (_key);
     frslot._peer = _peer;
     return ShallowCloneInternal(frslot);
 }
コード例 #5
0
ファイル: FreeSlotNode.cs プロジェクト: masroore/db4o
 internal static Tree RemoveGreaterOrEqual(FreeSlotNode
     a_in, TreeIntObject a_finder)
 {
     if (a_in == null)
     {
         return null;
     }
     var cmp = a_in._key - a_finder._key;
     if (cmp == 0)
     {
         a_finder._object = a_in;
         // the highest node in the hierarchy !!!
         return a_in.Remove();
     }
     if (cmp > 0)
     {
         a_in._preceding = RemoveGreaterOrEqual((FreeSlotNode
             ) a_in._preceding, a_finder);
         if (a_finder._object != null)
         {
             a_in._size--;
             return a_in;
         }
         a_finder._object = a_in;
         return a_in.Remove();
     }
     a_in._subsequent = RemoveGreaterOrEqual((FreeSlotNode
         ) a_in._subsequent, a_finder);
     if (a_finder._object != null)
     {
         a_in._size--;
     }
     return a_in;
 }
コード例 #6
0
        internal static Tree RemoveGreaterOrEqual(FreeSlotNode
                                                  a_in, TreeIntObject a_finder)
        {
            if (a_in == null)
            {
                return(null);
            }
            var cmp = a_in._key - a_finder._key;

            if (cmp == 0)
            {
                a_finder._object = a_in;
                // the highest node in the hierarchy !!!
                return(a_in.Remove());
            }
            if (cmp > 0)
            {
                a_in._preceding = RemoveGreaterOrEqual((FreeSlotNode
                                                        )a_in._preceding, a_finder);
                if (a_finder._object != null)
                {
                    a_in._size--;
                    return(a_in);
                }
                a_finder._object = a_in;
                return(a_in.Remove());
            }
            a_in._subsequent = RemoveGreaterOrEqual((FreeSlotNode
                                                     )a_in._subsequent, a_finder);
            if (a_finder._object != null)
            {
                a_in._size--;
            }
            return(a_in);
        }
コード例 #7
0
        private void DebugCheckBuffer(ByteArrayBuffer buffer, FreeSlotNode
                                      node)
        {
            if (!(buffer is StatefulBuffer))
            {
                return;
            }
            var trans = ((StatefulBuffer)buffer).Transaction();

            if (!(trans.Container() is IoAdaptedObjectContainer))
            {
                return;
            }
            var checker = trans.Container().CreateStatefulBuffer(trans, node._peer
                                                                 ._key, node._key);

            checker.Read();
            for (var i = 0; i < node._key; i++)
            {
                if (checker.ReadByte() != (byte)'X')
                {
                    Runtime.Out.WriteLine("!!! Free space corruption at:" + node._peer._key);
                    break;
                }
            }
        }
コード例 #8
0
        private void AddFreeSlotNodes(int address, int length)
        {
            FreeSlotNode addressNode = new FreeSlotNode(address);

            addressNode.CreatePeer(length);
            _freeByAddress = Tree.Add(_freeByAddress, addressNode);
            AddToFreeBySize(addressNode._peer);
        }
コード例 #9
0
            public void Visit(object a_object)
            {
                FreeSlotNode fsn     = (FreeSlotNode)a_object;
                int          address = fsn._key;
                int          length  = fsn._peer._key;

                visitor.Visit(new Slot(address, length));
            }
コード例 #10
0
        public override object ShallowClone()
        {
            var frslot = new FreeSlotNode
                             (_key);

            frslot._peer = _peer;
            return(ShallowCloneInternal(frslot));
        }
コード例 #11
0
        public override object Read(ByteArrayBuffer buffer)
        {
            var size    = buffer.ReadInt();
            var address = buffer.ReadInt();

            if (size > sizeLimit)
            {
                var node = new FreeSlotNode
                               (size);
                node.CreatePeer(address);
                if (Deploy.debug && Debug4.xbytes)
                {
                    DebugCheckBuffer(buffer, node);
                }
                return(node);
            }
            return(null);
        }
コード例 #12
0
        public override Slot AllocateTransactionLogSlot(int length)
        {
            FreeSlotNode sizeNode = (FreeSlotNode)Tree.Last(_freeBySize);

            if (sizeNode == null || sizeNode._key < length)
            {
                return(null);
            }
            // We can just be appending to the end of the file, using one
            // really big contigous slot that keeps growing. Let's limit.
            int limit = length + 100;

            if (sizeNode._key > limit)
            {
                return(AllocateSlot(limit));
            }
            RemoveFromBothTrees(sizeNode);
            return(new Slot(sizeNode._peer._key, sizeNode._key));
        }
コード例 #13
0
 private void AddToFreeBySize(FreeSlotNode node)
 {
     _freeBySize = Tree.Add(_freeBySize, node);
     _listener.SlotAdded(node._key);
 }
コード例 #14
0
 private void RemoveFromFreeBySize(FreeSlotNode node)
 {
     _freeBySize = _freeBySize.RemoveNode(node);
     _listener.SlotRemoved(node._key);
 }
コード例 #15
0
 private void RemoveFromBothTrees(FreeSlotNode sizeNode)
 {
     RemoveFromFreeBySize(sizeNode);
     _freeByAddress = _freeByAddress.RemoveNode(sizeNode._peer);
 }
コード例 #16
0
            public void Visit(object a_object)
            {
                FreeSlotNode node = ((FreeSlotNode)a_object)._peer;

                addressTree.value = Tree.Add(((Tree)addressTree.value), node);
            }
コード例 #17
0
		private void RemoveFromBothTrees(FreeSlotNode sizeNode)
		{
			RemoveFromFreeBySize(sizeNode);
			_freeByAddress = _freeByAddress.RemoveNode(sizeNode._peer);
		}
コード例 #18
0
 internal void CreatePeer(int a_key)
 {
     _peer       = new FreeSlotNode(a_key);
     _peer._peer = this;
 }
コード例 #19
0
ファイル: FreeSlotNode.cs プロジェクト: masroore/db4o
 public override object Read(ByteArrayBuffer buffer)
 {
     var size = buffer.ReadInt();
     var address = buffer.ReadInt();
     if (size > sizeLimit)
     {
         var node = new FreeSlotNode
             (size);
         node.CreatePeer(address);
         if (Deploy.debug && Debug4.xbytes)
         {
             DebugCheckBuffer(buffer, node);
         }
         return node;
     }
     return null;
 }
コード例 #20
0
		private void RemoveFromFreeBySize(FreeSlotNode node)
		{
			_freeBySize = _freeBySize.RemoveNode(node);
			_listener.SlotRemoved(node._key);
		}
コード例 #21
0
ファイル: FreeSlotNode.cs プロジェクト: masroore/db4o
 internal void CreatePeer(int a_key)
 {
     _peer = new FreeSlotNode(a_key);
     _peer._peer = this;
 }
コード例 #22
0
		private void AddToFreeBySize(FreeSlotNode node)
		{
			_freeBySize = Tree.Add(_freeBySize, node);
			_listener.SlotAdded(node._key);
		}
コード例 #23
0
ファイル: FreeSlotNode.cs プロジェクト: masroore/db4o
 private void DebugCheckBuffer(ByteArrayBuffer buffer, FreeSlotNode
     node)
 {
     if (!(buffer is StatefulBuffer))
     {
         return;
     }
     var trans = ((StatefulBuffer) buffer).Transaction();
     if (!(trans.Container() is IoAdaptedObjectContainer))
     {
         return;
     }
     var checker = trans.Container().CreateStatefulBuffer(trans, node._peer
         ._key, node._key);
     checker.Read();
     for (var i = 0; i < node._key; i++)
     {
         if (checker.ReadByte() != (byte) 'X')
         {
             Runtime.Out.WriteLine("!!! Free space corruption at:" + node._peer._key);
             break;
         }
     }
 }