// 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); }
// 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)); }
private void AddFreeSlotNodes(int address, int length) { FreeSlotNode addressNode = new FreeSlotNode(address); addressNode.CreatePeer(length); _freeByAddress = Tree.Add(_freeByAddress, addressNode); AddToFreeBySize(addressNode._peer); }
public override object ShallowClone() { var frslot = new FreeSlotNode (_key); frslot._peer = _peer; return ShallowCloneInternal(frslot); }
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; }
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); }
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; } } }
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)); }
public override object ShallowClone() { var frslot = new FreeSlotNode (_key); frslot._peer = _peer; return(ShallowCloneInternal(frslot)); }
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); }
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)); }
private void AddToFreeBySize(FreeSlotNode node) { _freeBySize = Tree.Add(_freeBySize, node); _listener.SlotAdded(node._key); }
private void RemoveFromFreeBySize(FreeSlotNode node) { _freeBySize = _freeBySize.RemoveNode(node); _listener.SlotRemoved(node._key); }
private void RemoveFromBothTrees(FreeSlotNode sizeNode) { RemoveFromFreeBySize(sizeNode); _freeByAddress = _freeByAddress.RemoveNode(sizeNode._peer); }
public void Visit(object a_object) { FreeSlotNode node = ((FreeSlotNode)a_object)._peer; addressTree.value = Tree.Add(((Tree)addressTree.value), node); }
internal void CreatePeer(int a_key) { _peer = new FreeSlotNode(a_key); _peer._peer = this; }
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; }
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; } } }