Example #1
0
 public LinkedRingBufferNode(LinkedRingBufferNode <A> previousNode, A item)
 {
     Item         = item;
     NextNode     = null;
     PreviousNode = previousNode;
     if (previousNode != null)
     {
         previousNode.NextNode = this;
     }
 }
Example #2
0
 /// <summary>
 /// Add item at the end of the buffer.
 /// If capacity is reached the link to the oldest item is deleted.
 /// </summary>
 public void Add(T item)
 {
     lock (Synchro)
     {
         /* create node and set to last one */
         var node = new LinkedRingBufferNode <T>(lastNode, item);
         lastNode = node;
         /* if it is the first node, the created is also the first */
         if (firstNode == null)
         {
             firstNode = node;
         }
         /* check for capacity reach */
         Count++;
         if (Count > Capacity)
         {
             /* deleted all links to the current first so that its eventually gc collected */
             Count     = Capacity;
             firstNode = firstNode.NextNode;
             firstNode.PreviousNode = null;
         }
     }
 }