public class circularbuffer: icollection, ienumerable, icollection, ienumerable
public circularbuffer(int capacity, bool allowoverflow)
public bool allowoverflow//緩衝器滿了以後是否允許溢位,即進行覆蓋
public int capacity//獲取或設定緩衝區大小
set}
public int size
}public bool contains(t item)
return false;
}public void clear()
public int put(t src)
public int put(t src, int offset, int count)//寫入資料,如果緩衝區不足且 allowoverflow為false,則丟擲異常
size = math.min(size + count, capacity);
return count;}}
public void put(t item)
}public void skip(int count)
}public t get(int count)
public int get(t dst)
public int get(t dst, int offset, int count)//讀取資料,如果緩衝區的資料少於要讀取的數量,則只讀取剩餘的數量
size -= realcount;
return realcount;}}
public t get()
}public void copyto(t array)
public void copyto(t array, int arrayindex)
public void copyto(int index, t array, int arrayindex, int count)//拷貝緩衝區的資料到指定陣列的指定位置,如果緩衝區的數量不足,則丟擲異常
}public ienumeratorgetenumerator()
}public t getbuffer()
public t toarray()
#region icollectionmembers
int icollection.count
}bool icollection.isreadonly
}void icollection.add(t item)
bool icollection.remove(t item)
#endregion
#region ienumerablemembers
ienumeratorienumerable.getenumerator()
#endregion
#region icollection members
int icollection.count
}bool icollection.issynchronized
}object icollection.syncroot
}void icollection.copyto(array array, int arrayindex)
#endregion
#region ienumerable members
ienumerator ienumerable.getenumerator()
#endregion
}
環形緩衝區
include include include include include define buffsize 1024 1024 define min x,y x y x y pthread mutex t lock pthread mutex initializer struct cycle b...
環形緩衝區
define print buf size 16 1024 static char g pcnetprintbuf 環形緩衝區的首位址 static int g ireadpos 0 環形緩衝區讀的位置 static int g iwritepos 0 環形緩衝區寫的位置 intinit 判斷環形緩...
環形緩衝區
環形緩衝區要維護兩個索引,分別對應寫入端 w 和讀取端 r 寫入 push 的時候,先確保環沒滿,然後把資料複製到 w 所對應的元素,最後 w 指向下乙個元素 讀取 pop 的時候,先確保環沒空,然後返回 r 對應的元素,最後 r 指向下乙個元素。上述的操作並不複雜,不過有乙個小小的麻煩 空環和滿環...