public void TestAppend() { int RDATA_SIZE = 256; Fifo<byte> rdata = new Fifo<byte>(RDATA_SIZE); byte[] inData = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }; byte[] inData2 = new byte[] { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9 }; rdata.Append(inData); Assert.AreEqual(rdata.FreeSpace(), RDATA_SIZE - inData.Length); Assert.AreEqual(rdata.Size(), inData.Length); for (int i = 0; i < inData.Length; i++) Assert.AreEqual(rdata.Peek()[i], inData[i]); rdata.Append(inData2); byte[] inDataAll = inData.Concat(inData2).ToArray(); Assert.AreEqual(rdata.FreeSpace(), RDATA_SIZE - inDataAll.Length); Assert.AreEqual(rdata.Size(), inDataAll.Length); for (int i = 0; i < inDataAll.Length; i++) Assert.AreEqual(rdata.Peek()[i], inDataAll[i]); rdata.Resize(RDATA_SIZE * 2); Assert.AreEqual(rdata.FreeSpace(), RDATA_SIZE * 2 - inDataAll.Length); Assert.AreEqual(rdata.Size(), inDataAll.Length); for (int i = 0; i < inDataAll.Length; i++) Assert.AreEqual(rdata.Peek()[i], inDataAll[i]); byte[] outData = rdata.Take(); Assert.AreEqual(outData.Length, inDataAll.Length); for (int i = 0; i < inDataAll.Length; i++) Assert.AreEqual(outData[i], inDataAll[i]); }
public void FifoTestOneAsset() { var transaction = new Transaction { SharesSold = 100, PricePerShare = 10.5m, Selldate = new DateTime(2005, 2, 3) }; var fifo = new Fifo(); var assets = Assets.Take(1).ToList(); var costPrice = fifo.CostPriceOfSharesSoldAndSharesRemaining(transaction, assets); Assert.AreEqual(10.0m, costPrice.CostPriceSold); }
public void FifoTestOneAssetSellMoreSharesThanOwn() { var transaction = new Transaction { SharesSold = 120, PricePerShare = 10.5m, Selldate = new DateTime(2005, 2, 3) }; var fifo = new Fifo(); var assets = Assets.Take(1).ToList(); Action action = () => fifo.CostPriceOfSharesSoldAndSharesRemaining(transaction, assets); Assert.ThrowsException <ArgumentOutOfRangeException>(action); }
public void FifoTest140SharesSoldSpecifyingDateInMiddleOfTransactions() { var transaction = new Transaction { SharesSold = 100, PricePerShare = 10.5m, Selldate = new DateTime(2005, 1, 3) }; var fifo = new Fifo(); var assets = Assets; var costPrice = fifo.CostPriceOfSharesSoldAndSharesRemaining(transaction, assets); Assert.AreEqual(1000.0m / 100.0m, costPrice.CostPriceSold); }
/// <summary> /// Gets the size of a pipe /// </summary> /// <param name="node">The pipe node</param> /// <returns>The size</returns> private static uint getSizeImpl(Node node) { PipeFSCookie cookie = (PipeFSCookie)node.Cookie; if (cookie == null) { return(0); } Fifo fifo = cookie.Fifo; return(fifo.AvailableBytes); }
public SockSess(Socket sock, int stall = BASE_STALL) { this.sock = sock; this.eof = false; this.stall = stall; this.tick = DateTime.Now; this.id = Guid.NewGuid().ToString(); this.conntime = tick; rfifo = new Fifo <byte>(); wfifo = new Fifo <byte>(); sdata = null; recv_event = null; close_event = null; }
private void Semicolon() { int first = CompilingStart.Pop(), last = Code.Count - 1; void wordListActor() { returning = false; for (int i = first; (i <= last) && !returning; i++) { Code[i](); } returning = false; } Contexts.Top[1][CompilingName.Pop()] = wordListActor; End(); }
/// <summary> /// Request a new audio buffer /// </summary> /// <param name="size">The required size</param> /// <param name="buffer">The buffer to put the data into</param> public unsafe static void RequestBuffer(uint size, ushort[] buffer) { fixed(ushort *ptr = m_tmpBuffer) Memory.Memclear(ptr, BufferSize * sizeof(ushort)); for (int i = 0; i < m_buffers.Count; i++) { Fifo fifo = (Fifo)m_buffers.Item[i]; uint read = fifo.Read(Util.PtrToArray((byte *)Util.ObjectToVoidPtr(m_tmpBuffer)), size * sizeof(ushort)); for (int j = 0; j < /*read / 2*/ BufferSize; j++) { buffer[j] = (ushort)((m_tmpBuffer[j] >> 8) | (m_tmpBuffer[j] & 0xFF)); } } }
/// <summary> /// Initialize keyboard /// </summary> public static unsafe void Init() { m_fifo = new Fifo(250, true); // Install the IRQ handler IRQ.SetHandler(1, handler); IOApicManager.CreateISARedirection(1, 1); Node node = new Node(); node.Read = readImpl; node.GetSize = getSizeImpl; node.Flags = NodeFlags.DEVICE | NodeFlags.FILE; RootPoint dev = new RootPoint("keyboard", node); VFS.MountPointDevFS.AddEntry(dev); }
static void TestFifo() { Fifo a = new Fifo(); Fifo <byte> b = new Fifo <byte>(); int num = 0; int standard = 10; while (true) { num++; if ((num % 100) == 0) { WriteLine($"num = {num}, len = {b.Size}, a = {a.PhysicalSize} ({(int)((double)a.Size * 100 / (double)a.PhysicalSize)} %) b = {b.PhysicalSize} ({(int)((double)b.Size * 100 / (double)b.PhysicalSize)} %) "); } byte[] add_data = new byte[WebSocketHelper.RandSInt31() % standard]; WebSocketHelper.Rand(add_data); a.Write(add_data); b.Write(add_data); if (a.Span.SequenceCompareTo(b.Span) != 0) { throw new Exception(); } int read_size = WebSocketHelper.RandSInt31() % (int)((double)standard * 1.1); var reta = a.Read(read_size); var retb = b.Read(read_size); if (reta.AsSpan().SequenceCompareTo(retb) != 0) { throw new Exception(); } if (a.Size != b.Size) { throw new Exception(); } } }
public SetAssociativeCacheViewModel UpdateCache() { Boolean isFull = true; Int32 cacheLine = _GetCurrentIndex(); //asta e de fapt setul SetAssociativeCacheLineViewModel cacheLineToBeReplaced = GetCacheLineToBeReplaced(); for (var set = 0; set < SimulationParameters.SetCount; set++) { if (CacheViewModel.Cache[set].CacheLines[cacheLine] == null) { isFull = false; break; } } if (isFull) { if (isFull && SimulationParameters.ReplacementAlgorithm == ReplacementAlgorithm.LFU) { CacheViewModel.Cache[cacheLineToBeReplaced.Set].CacheUpdateTypeMessage = "Copying data to least frequently used cache line."; } else if (isFull && SimulationParameters.ReplacementAlgorithm == ReplacementAlgorithm.LRU) { CacheViewModel.Cache[cacheLineToBeReplaced.Set].CacheUpdateTypeMessage = "Copying data to least recently used cache line."; } else if (isFull && SimulationParameters.ReplacementAlgorithm == ReplacementAlgorithm.FIFO) { CacheViewModel.Cache[cacheLineToBeReplaced.Set].CacheUpdateTypeMessage = "Copying data to first cache line updated."; Fifo.RemoveAt(0); } } else { //Fifo.Add(cacheLineToBeReplaced.Set, cacheLineToBeReplaced.Index); CacheViewModel.Cache[cacheLineToBeReplaced.Set].CacheUpdateTypeMessage = "Copying data to an unused cache line."; } _PlaceDataAtIndex(cacheLineToBeReplaced.Index, cacheLineToBeReplaced.Set); CacheViewModel.LastUpdatedSet = cacheLineToBeReplaced.Set; return(CacheViewModel); }
/// <a href="http://bit.ly/2QR9rF8"></a> <inheritdoc /> protected override void BuildSelector() { Fifo <string> choices = new Fifo <string>(); base.BuildSelector(); // renews Choices Rtf(choices, Selector.Choices); for (var i = 0; i < quoteFiles.Length; i++) { if (quoteFiles[0] != null) { Rtf(choices, quoteFiles[i].text.Split('\n')); } } if (choices.Count > 0) { Selector.Choices = choices.ToArray(); } }
public void TestAppend() { int RDATA_SIZE = 256; Fifo <byte> rdata = new Fifo <byte>(RDATA_SIZE); byte[] inData = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99 }; byte[] inData2 = new byte[] { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9 }; rdata.Append(inData); Assert.AreEqual(rdata.FreeSpace(), RDATA_SIZE - inData.Length); Assert.AreEqual(rdata.Size(), inData.Length); for (int i = 0; i < inData.Length; i++) { Assert.AreEqual(rdata.Peek()[i], inData[i]); } rdata.Append(inData2); byte[] inDataAll = inData.Concat(inData2).ToArray(); Assert.AreEqual(rdata.FreeSpace(), RDATA_SIZE - inDataAll.Length); Assert.AreEqual(rdata.Size(), inDataAll.Length); for (int i = 0; i < inDataAll.Length; i++) { Assert.AreEqual(rdata.Peek()[i], inDataAll[i]); } rdata.Resize(RDATA_SIZE * 2); Assert.AreEqual(rdata.FreeSpace(), RDATA_SIZE * 2 - inDataAll.Length); Assert.AreEqual(rdata.Size(), inDataAll.Length); for (int i = 0; i < inDataAll.Length; i++) { Assert.AreEqual(rdata.Peek()[i], inDataAll[i]); } byte[] outData = rdata.Take(); Assert.AreEqual(outData.Length, inDataAll.Length); for (int i = 0; i < inDataAll.Length; i++) { Assert.AreEqual(outData[i], inDataAll[i]); } }
public override void Stop() { if (iThreadHandle != null && iThreadNetwork != null) { iThreadNetworkAbort = true; iServer.Shutdown(); lock (iActiveSessionStreams) { for (int i = 0; i < iActiveSessionStreams.Count; i++) { iActiveSessionStreams[i].Close(); } iActiveSessionStreams.Clear(); } iScheduler.Stop(); iThreadNetwork.Join(); iThreadNetwork = null; iServer.Close(); iThreadHandleAbort = true; iEventFifo.Push(null); iThreadHandle.Join(); iThreadHandle = null; lock (iSessions) { iSessions.Clear(); } iEventFifo = new Fifo <Event>(); Trace.WriteLine(Trace.kUpnp, "EventServerUpnp.Stop() successful"); } else { Trace.WriteLine(Trace.kUpnp, "EventServerUpnp.Stop() already stopped - silently do nothing"); } }
public GZipPacker() { fifo = new Fifo(); zs = new ZStream(); zs.deflateInit(-1, -15); this.currentSize = 0; this.crc32 = 0xffffffff; this.finished = false; GZipHeader h = new GZipHeader(); h.ID1 = 0x1f; h.ID2 = 0x8b; h.FLG = 0; h.MTIME = (uint)Util.DateTimeToUnixTime(DateTime.Now.ToUniversalTime()); h.XFL = 0; h.OS = 3; h.CM = 8; fifo.Write(Util.Legacy_StructToByte(h)); }
public TarPacker(Encoding encoding) { fifo = new Fifo(); dirList = new Dictionary <string, int>(StrComparer.SensitiveCaseComparer); this.encoding = encoding; }
/// <summary> /// Creates a new AudioDataCookie /// </summary> /// <param name="bufferSize">Buffer size</param> public AudioDataCookie(int bufferSize) { Buffer = new Fifo(bufferSize, false); }
public ZipPacker() { fifo = new Fifo(); fileList = new List <File>(); }
static void BenchStreamBuffer() { FastStreamBuffer <byte> new_test_buf(int num = 1) { FastStreamBuffer <byte> ret = new FastStreamBuffer <byte>(); for (int i = 0; i < num; i++) { ret.Enqueue(new byte[] { 1, 2, 3, }); ret.Enqueue(new byte[] { 4, 5, 6, 7 }); ret.Enqueue(new byte[] { 8, 9, 10, 11, 12 }); ret.Enqueue(new byte[] { 13, 14, 15, 16, 17, 18 }); } return(ret); } MicroBenchmarkQueue q = new MicroBenchmarkQueue(); int num_test_data = 10000; object[] test_data_array = new object[num_test_data]; for (int i = 0; i < num_test_data; i++) { test_data_array[i] = new object(); } q.Add(new MicroBenchmark <int>("Queue insert test: .NET Queue", 10000, (x, iterations) => { Queue <object> queue = new Queue <object>(); for (int i = 0; i < iterations; i++) { foreach (object o in test_data_array) { queue.Enqueue(o); } } }, () => 0), true, 0); q.Add(new MicroBenchmark <int>("Queue insert test: Fifo<T>", 10000, (x, iterations) => { Fifo <object> fifo = new Fifo <object>(); var span = test_data_array.AsSpan(); for (int i = 0; i < iterations; i++) { fifo.Write(span); } }, () => 0), true, 0); q.Add(new MicroBenchmark <int>("InsertFirst", 1000, (x, iterations) => { List <int> rands = new List <int>(); for (int i = 0; i < 256; i++) { rands.Add(WebSocketHelper.RandSInt31()); } Memory <byte> add_data = new byte[] { 1, 2, 3, 4, 5, }; FastStreamBuffer <byte> buf = new_test_buf(); for (int i = 0; i < iterations; i++) { //buf.Insert(buf.PinHead + 0, add_data); buf.InsertHead(add_data); } }, () => 0), true, 0); q.Add(new MicroBenchmark <int>("InsertAndRemoveRandom", 10000, (x, iterations) => { List <int> rands = new List <int>(); for (int i = 0; i < 256; i++) { rands.Add(WebSocketHelper.RandSInt31()); } Memory <byte> add_data = new byte[] { 1, 2, 3, 4, 5, }; FastStreamBuffer <byte> buf = new_test_buf(); for (int i = 0; i < iterations; i++) { long pin = buf.PinHead + rands[i % rands.Count] % (buf.Length - add_data.Length); buf.Insert(pin, add_data); buf.Remove(pin, add_data.Length); } }, () => 0), true, 0); q.Add(new MicroBenchmark <int>("EnqueueAndDequeue", 10000, (x, iterations) => { List <int> rands = new List <int>(); for (int i = 0; i < 256; i++) { rands.Add(WebSocketHelper.RandSInt31()); } Memory <byte> add_data = new byte[] { 1, 2, 3, 4, 5, }; FastStreamBuffer <byte> buf = new_test_buf(); for (int i = 0; i < iterations; i++) { buf.Enqueue(add_data); var ret = buf.Dequeue(long.MaxValue, out _, false); } }, () => 0), true, 10); FastStreamBuffer <byte> bufx1 = new_test_buf(10000); FastStreamBuffer <byte> bufx2 = new_test_buf(10000); q.Add(new MicroBenchmark <int>("MoveToOtherEmpty", 100000, (x, iterations) => { for (int i = 0; i < iterations; i++) { bufx1.DequeueAllAndEnqueueToOther(bufx2); bufx2.DequeueAllAndEnqueueToOther(bufx1); } }, () => 0), true, 20); System.GC.Collect(); q.Add(new MicroBenchmark <int>("MoveToOtherNonEmpty", 1, (x, iterations) => { FastStreamBuffer <byte> buf1 = new_test_buf(10000); FastStreamBuffer <byte> buf2 = new_test_buf(10000); for (int i = 0; i < iterations; i++) { buf1.DequeueAllAndEnqueueToOther(buf2); } }, () => 0), true, 20); bool call_deque = true; long deque_max = 1; q.Add(new MicroBenchmark <int>("Datagram1_single_add", 10000, (x, iterations) => { FastDatagramBuffer <int> dg = new FastDatagramBuffer <int>(); for (int i = 0; i < iterations; i++) { dg.Enqueue(i); } if (call_deque) { for (int i = 0; i < iterations; i++) { var r = dg.Dequeue(deque_max, out long _); } } }, () => 0), true, 30); q.Add(new MicroBenchmark <int>("Datagram1_bulk_add", 10000, (x, iterations) => { FastDatagramBuffer <int> dg = new FastDatagramBuffer <int>(); int[] tmp = new int[100]; for (int i = 0; i < iterations; i++) { dg.EnqueueAll(tmp); } if (call_deque) { for (int i = 0; i < iterations; i++) { var r = dg.Dequeue(deque_max, out long _); } } }, () => 0), true, 30); q.Run(); }
public SetAssociativeCacheLineViewModel GetCacheLineToBeReplaced() { Int32 cacheLine = _GetCurrentIndex(); //asta e de fapt setul Boolean isFull = true; Int32 setCount = 0; Int32 indexCount = 0; for (var set = 0; set < SimulationParameters.SetCount; set++) { if (CacheViewModel.Cache[set].CacheLines[cacheLine] == null) { Fifo.Add(new KeyValuePair <int, int>(cacheLine, set)); isFull = false; setCount = set; indexCount = cacheLine; break; } } if (isFull && SimulationParameters.ReplacementAlgorithm == ReplacementAlgorithm.LFU) { IList <Int32> setFrequencies = CacheLineFrequencies[cacheLine]; Int32 frequency = setFrequencies[0]; Int32 replacedIndexFromSet = 0; for (var index = 1; index < setFrequencies.Count; index++) { if (setFrequencies[index] < frequency) { replacedIndexFromSet = index; frequency = setFrequencies[index]; } } setCount = replacedIndexFromSet; indexCount = cacheLine; } else if (SimulationParameters.ReplacementAlgorithm == ReplacementAlgorithm.LRU) { IList <Int32> setUsageTimes = CacheLineLastUsageTimes[cacheLine]; Int32 usageTime = setUsageTimes[0]; Int32 replacedIndexFromSet = 0; for (var index = 1; index < setUsageTimes.Count; index++) { if (setUsageTimes[index] < usageTime) { replacedIndexFromSet = index; usageTime = setUsageTimes[index]; } } setCount = replacedIndexFromSet; indexCount = cacheLine; } else if (SimulationParameters.ReplacementAlgorithm == ReplacementAlgorithm.FIFO) { setCount = Fifo[0].Value; indexCount = Fifo[0].Key; } return(new SetAssociativeCacheLineViewModel { Set = setCount, Index = indexCount }); }