Talk:Circular buffer

message: Try putting 1..N, followed by getting 1..N times, then try putting, where the buffer is empty shows it is full.  — Preceding unsigned comment added by 4ureyz (talk • contribs) 18:18, 25 November 2023 (UTC)
thread_title:  The C implementation is wrong 

message: The template queue's IsFull function is incorrect.  Notice it is identical to IsEmpty(), only advancing the tail before doing a check. Consider:  Q::Resize(2); Q::Enqueue(T); Q::Enqueue(T); The second enqueue will throw as IsFull reports true (tail=1, +1 & mask = head == true)  — Preceding unsigned comment added by 98.232.107.82 (talk) 23:09, 12 June 2011 (UTC)
thread_title:  IsFull function is incorrect 

message: When was the ring buffer invented or first publicly discussed or first mentioned in an academic paper or first used in an actual operating system? 209.252.104.131 (talk) 10:47, 16 March 2008 (UTC)
replies: text: Ringbuffers did exist before Linux. The keyboard buffer of a IBM PC is a ringbuffer as well with  either 14 or 16 bytes in size (don't remember the actual size) and when it's full the speaker beeps to indicate this.--91.34.84.81 (talk) 22:24, 3 December 2014 (UTC)
replies: text:  I have code written in 1983 that uses them and calls them "rings", and I suspect that they are *much* older than that, but I don't have time to investigate. Vincent J. Lipsio (talk) 23:02, 3 December 2014 (UTC)
replies: text: Here's a 1973 paper that discusses ring buffers. Without reference or claim of originality, which suggests they were common knowledge back then. QVVERTYVS (hm?) 15:35, 4 December 2014 (UTC)
replies: text:  Here's a video of a late 1950s patented German mechanical telephone equipment that functions very similarly to a circular buffer. The device stores telephone pulse signals in a circular ring and features a producer and consumer operating independently of one another. This suggests the idea and the use case of circular buffers was around even then. 115.134.249.202 (talk) 12:58, 20 November 2021 (UTC)
thread_title:  history 

message: In Circular buffer mechanics it talks about a "buffer border". What is the buffer border and when can it be "read over"? 137.44.2.188 (talk) 09:51, 9 April 2008 (UTC)
thread_title:  Buffer border 

message: The RRDtool currently mentions a "a round-robin archive (RRA).", and the brief description reminds me of a circular buffer.
Is "round-robin archive" an exact synonym for "circular buffer", or some specific variant of a circular buffer?
Or is it something significantly different?
--68.0.124.33 (talk) 00:49, 15 January 2009 (UTC)
thread_title:  round robin archive 

message: When checking to see how much space is used in the buffer, needing to be read (The space between the write and read pointers) could you not just use another variable, incrementing it as you write something, and decrementing it as you read something? For example, once it is initialized, the buffer is empty therefore your variable would = 0. But once you write, say 3 bytes, with out reading something, the variable would than = 3. And again after reading 2 bytes, that same variable would equal 1, effectively indicating that there is one byte remaining to be read in the buffer. This eliminates the need for any crazy algorithms for when your write pointer has wrapped around before you read pointer has.  —Preceding unsigned comment added by 205.250.74.174 (talk) 23:15, 17 June 2009 (UTC)
thread_title: Used Buffer space

message: I find the C# example distinctly uninformative and overly verbose. While perhaps it shows good design, it doesn't illustrate the subject matter any better than the other two C examples. I'm removing it for now. SiegeLord (talk) 18:33, 13 September 2010 (UTC)
thread_title:  C# Example 

message: Another solution not mentioned in the article is to have an additional boolean variable. When an element is inserted, it is set to true, and when an element is removed, it is set to false. If the indices are equal and the variable is true, the buffer is full. If the indices are equal and the varaible is false, the buffer is empty. Platypus1130 (talk) 21:58, 30 January 2011 (UTC)
thread_title:  Full/Empty Buffer Distinction 

message: Please don't replace the C code with some pseudo code which doesnt really help anybody...  — Preceding unsigned comment added by 130.149.245.245 (talk) 16:17, 19 December 2012 (UTC)
replies: text: Is there a way we could put the code into some kind of infobox structure that by default would be closed, but could be opened by the user if they wanted?  I don't know what WikiMarkup has for this kind of thing, but I know I've seen it on a couple of articles before.  Then perhaps put some short psudocode in the boy, with a full/more complete C implementation in the closed box.  I don't know whether you could do a psudocode in 10 lines, I'm thinking along these lines:
  Initialization:
  p1=0; p2=0; numItems=0; isFull=false; isEmpty=true;
  Function put(x):
    array[p1] = x; p1++; numItems++;  // insert item and advance write pointer
  Function get():
    return array[p2]; p2++; numItems--;  // remove item and advance read pointer
  With either function:
    if (p1= arrayLength) then p1 = 0;  // reset write pointer to beginning if we've reached the end ("ring" around)
    if (p2= arrayLength) then p2 = 0;  // same for read pointer
    if (p1<0) then p1 = arrayLength;  // reset write pointer to end of buffer if we've reached the beginning
    if (p2<0) then p2 = arrayLength;  // same for read pointer
    if (numItems >= arrayLength) then isFull = true; isEmpty = false;  // check if we've filled all spaces
    if (numItems <= 0) then isEmpty = true; isFull = false;  // check if we've read from all spaces
  Function isFull(): return isFull  // return whether the buffer is full or empty
  Function isEmpty(): return isEmpty
I just wrote that off the top of my head.  It's not really "proper psudocode" - and I'm not even sure it will work correctly - I'm pretty sure that the isFull and isEmpty logic isn't right. But something like that.  — Preceding unsigned comment added by Jimw338 (talk • contribs) 19:40, 9 August 2012 (UTC)
thread_title:  Full implementation? 

message: I'm a little surprised to see my Bip Buffer article removed from here (not that I added it, but I was quite honored that it was linked). It was removed during removal of specific implementations... except it's not an actual implementation per se - it's a variant algorithm which provides nearly the efficiency of a regular circular buffer, but with reduced overhead for reading data in chunks; it ensures that all chunks read are contiguous.Fleetingshadow (talk) 22:15, 7 September 2011 (UTC)
replies: text: MrOllie, this is collateral damage from our discussion above. Is there anything I can say to make you restore these links? --Tennenrishin (talk) 08:46, 8 September 2011 (UTC)
replies: text:  Regardless of the quality of such articles and ideas, Wikipedia needs to be consistent with its No Original Research policy. There are plenty of great venues for advancing new code paradigms/data structures/algorithms, etc. This just isn't the place for it. 02:48, 10 September 2011 (UTC)
replies: text:  I added a brief mention of the Bip Buffer, with a reference link, not realizing that this had already been discussed. I hope this doesn't trigger any unpleasantness. --DavidCary (talk) 05:35, 30 October 2012 (UTC)

text:  I just came here to review the C implementation and, for the first time in a decade, I had to look at older revisions of the page to get value from a Wikipedia article.  You guys should really put that back. It's the most useful part of this page and conveys ideas cleanly. -ml  — Preceding unsigned comment added by 70.36.56.149 (talk) 00:50, 6 February 2015 (UTC)
thread_title:  Removal of Implementations 

message: I think the "Uses"-part is too black-and-white as it is...
:"If a non-circular buffer were used then it would be necessary to shift all elements when one is consumed."
Wrong, just use a pointer to the start of the buffer. The circularity just helps in reclaiming the dead space in front of such a buffer.
:"Circular buffering makes a good implementation strategy for a queue that has fixed maximum size.
Wrong if the queue almost never uses the maximum size.
: "For arbitrarily expanding queues, a Linked list approach may be preferred instead."
Yes, but Linked lists have a huge space (and sometimes cache miss) overhead, and a performance penalty because of the indirections, while a Circular buffer can be almost as fast as an Array. So the "may" is strong in this one.
Bottom line, the claims are more or less correct, but they do not reflect the fine distinctions necessary to choose a data structure in the real world. Also, there are applications in some scheduling algorithms, and the multimedia example can be generalized to the synchronization of many more single-producer-single-consumer-cases.
Sorry I'm only criticizing, and not editing, but my English is not good enough for that... --89.204.152.53 (talk) 04:36, 8 August 2013 (UTC)
thread_title:  Uses 

message: I'm surprised to see the Optimized POSIX implementation example being removed from the article on April 14, 2014. This example is extremely useful, well written, and provides a great benefit to readers. Please consider restoring it. --Victorspm (talk) 17:53, 21 April 2014 (UTC)
replies: text: Wikipedia is an encyclopedia, not a code repository. That piece of code was a clear piece of original research. WP isn't a good place to share code: it has the wrong license and it doesn't have sufficient quality control. QVVERTYVS (hm?) 16:04, 4 December 2014 (UTC)

text: For anyone else that might stumble upon this, I implemented a slightly improved version (see set_up_mirroring()) based on the original version from the article. Hardcoding /dev/shm and hoping the file ends up in an in-memory filesystem can be avoided by using the POSIX shared memory shm_open() and shm_unlink() functions. -- Ulfalizer (talk) 23:12, 30 January 2015 (UTC)

text: So, taking into account that the discussed piece of code is available only in the history of this page, I have uploaded a bit modified copy of this excellent and valuable piece of code here . --Vitaly.v.ch (talk) 20:18, 1 February 2020 (UTC)
thread_title:  Removal of Optimized POSIX implementation 

message: From the desciption of a 1950s telephone exchange I quote: "The mechanical storage element of the pulse repeater is a lamellar disc with 72 resilient lamellae which is rotatably arranged in a raceway.
The storage magnet turns the disc one step further with each incoming pulse. The marker magnet presses the lamellas on one side of the ring when the magnet is attracted and on the other side of the ring when the magnet has fallen off. These markings are retained for one full turn of the flap disc and thus mark the end of a previously stored series of pulses. Up to the start of withdrawal, 64 pulses can be saved. The scanning arm is on the other side (scanning side). This arm moves with the lamellar disc when it is stored. When releasing, the scanning arm slides over the lamellar support ring against the rotary movement of the lamellar disk and thereby scans each lamellar step until it is stopped at the end of the series of marked lamellas." See https://www.youtube.com/watch?v=_xI9tXi-UNs for the german original text.
From the US patent 3979733 I quote: "Responsive to clock signal CK1 and the coincidence of the comparator and input enable signals on lead 302, the contents of the read address register are incremented by adder 350. Thereby the contents of the read address register are advanced to correspond to the direct address of the next of the consecutive memory cells in the FIFO queue, i.e., the cell from which a packet may next be read ... Thereafter, responsive to clock signal CK3 and the coincidence of the comparator and input enable signals, the contents of the write address register are incremented by adder 350. Thereby the contents of the write address register are advanced to correspond to the direct address of the next available memory cell in the FIFO queue, i.e., the next cell into which a packet may be written."
Is it necessary to put this quote into the Wikimedia article? I am sure that a 1976 patent is not the first document about circular buffer. The original inventor of circular buffer is not known to me, I think the name got lost in history. Can we now put down the "needs additional citations" sign? AndreAdrian (talk) 11:31, 15 December 2021 (UTC)
thread_title:  needs additional citations? 

message: The article cites an example in which consecutive virtual memory pages are mapped to the same buffer for apparent performance improvement as "automatic" wrap around is managed by hardware. However it is not necessarily true that virtual memory homonyms are performantly accessed. In fact, mapping in this fashion may significantly slow stores to the buffer on modern CPUs (and other hardware). At a minimum, a citation showing how this improves performance is needed.  — Preceding unsigned comment added by Jcm (talk • contribs) 16:25, 23 January 2022 (UTC)
replies: text: I believe that the performance problems exist for virtual memory homonyms, as you say, but the technique here is actually virtual memory synonyms or aliasing. See https://www.cse.unsw.edu.au/~cs9242/02/lectures/03-cache/node8.html. I think it is reasonable to assume that offloading this to hardware will be faster, but I can try cooking up a little benchmark. 74.109.39.81 (talk) 03:14, 26 May 2024 (UTC)
thread_title:  Optimization