public MemorySpace(uint startAddress, uint size, bool free, MemorySpace prev, MemorySpace next) { this.StartAddress = startAddress; this.EndAddress = startAddress + size - 1; this.Free = free; this.SetAdjacentMemorySpaces(prev, next); }
public MemorySpace(bool free, uint startAddress, uint endAddress, MemorySpace prev, MemorySpace next) { this.StartAddress = startAddress; this.EndAddress = endAddress; this.Free = free; this.SetAdjacentMemorySpaces(prev, next); }
public void ConstructorTests() { var m = new MemorySpace(0, 100); Assert.Equal(100u, m.Size); Assert.Equal(0u, m.StartAddress); Assert.Equal(99u, m.EndAddress); Assert.False(m.Free); Assert.Null(m.Next); Assert.Null(m.Previous); m = new MemorySpace(true, 0, 99); Assert.Equal(100u, m.Size); Assert.Equal(0u, m.StartAddress); Assert.Equal(99u, m.EndAddress); Assert.True(m.Free); Assert.Null(m.Next); Assert.Null(m.Previous); m = new MemorySpace(0, 100, false); Assert.Equal(100u, m.Size); Assert.Equal(0u, m.StartAddress); Assert.Equal(99u, m.EndAddress); Assert.False(m.Free); Assert.Null(m.Next); Assert.Null(m.Previous); var prev = new MemorySpace(0, 0); var next = new MemorySpace(0, 0); m = new MemorySpace(false, 0, 99, prev, next); Assert.Equal(100u, m.Size); Assert.Equal(0u, m.StartAddress); Assert.Equal(99u, m.EndAddress); Assert.False(m.Free); Assert.Equal(next, m.Next); Assert.Equal(prev, m.Previous); Assert.Equal(m, next.Previous); Assert.Equal(m, prev.Next); prev = new MemorySpace(0, 0); next = new MemorySpace(0, 0); m = new MemorySpace(0, 100,false, prev, next); Assert.Equal(100u, m.Size); Assert.Equal(0u, m.StartAddress); Assert.Equal(99u, m.EndAddress); Assert.False(m.Free); Assert.Equal(next, m.Next); Assert.Equal(prev, m.Previous); Assert.Equal(m, next.Previous); Assert.Equal(m, prev.Next); }
private static MemorySpace Slice(uint size, MemorySpace n) { //size should always be >= n.Size uint nSize = n.Size; n.Free = false; if (nSize == size) return n; //resize it n.Size = size; //insert new memory space in between new MemorySpace(n.EndAddress + 1, nSize - n.Size, true, n, n.Next); return n; }
public void SizeChange() { var m = new MemorySpace(0, 100); Assert.Equal(100u, m.Size); Assert.Equal(0u, m.StartAddress); Assert.Equal(99u, m.EndAddress); Assert.False(m.Free); Assert.Null(m.Next); Assert.Null(m.Previous); m.Size = 30; Assert.Equal(30u, m.Size); Assert.Equal(0u, m.StartAddress); Assert.Equal(29u, m.EndAddress); Assert.False(m.Free); Assert.Null(m.Next); Assert.Null(m.Previous); }
public void FreeMemory(MemorySpace space) { space.Free = true; }
protected MemorySegment(uint startAddress, uint size) { First = new MemorySpace(startAddress, size, true); this.Length = size; }
private void SetAdjacentMemorySpaces(MemorySpace prev, MemorySpace next) { if (prev != null) { this.Previous = prev; prev.Next = this; } if (next == null) return; this.Next = next; next.Previous = this; }