circular-buffer

How to best sort a portion of a circular buffer?

I have a circular, statically allocated buffer in C, which I'm using as a queue for a depth breadth first search. I'd like have the top N elements in the queue sorted. It would be easy to just use a regular qsort() - except it's a circular buffer, and the top N elements might wrap around. I could, of course, write my own sorting implemen...

Simplified algorithm for calculating remaining space in a circular buffer?

I was wonder if there is a simpler (single) way to calculate the remaining space in a circular buffer than this? int remaining = (end > start) ? end-start : bufferSize - start + end; ...

How would YOU do/write this homework assignment? (theoretical)

I'm not asking for anyone to do this homework for me, but I bring it up because it's a very good practical introduction to C# and threading, but at the same time I feel it's perhaps a little too simple. Is this really the best way to teach threading? what key threading concepts are "lost" in this exercize, what would new programmers u...

How do you implement a circular buffer in C?

I have a need for a fixed-size (selectable at run-time when creating it, not compile-time) circular buffer which can hold objects of any type and it needs to be very high performance. I don't think there will be resource contention issues since, although it's in a multi-tasking embedded environment, it's a co-operative one so the tasks t...

CircularBuffer IDictionary in C#?

I need a CircularBuffer IDictionary. Can anyone point me to a good open source implementation. So a IDictionary that has a maximum capacity, say configured to 100 items, which when item 101 is added the original first item is popped/removed from the dictionary thus ensuring the item count never exceeds 100. Thanks ...

Where can I find a good Delphi or Object Pascal implementation for a circular buffer

My main purpose is to have a generic data buffer that I can use for transfers. I'm thinking of something along the lines of what XCopy did. Is there something already made out there or a good example one can follow? ...

Do any Java libraries provide a random access Queue implementation?

I'm implementing a sliding window over a stream of events, in Java. So I want a data structure which allows me to do the following: add to the end of the data structure when new events occur; remove from the start of the data structure when old events are processed; get standard random access (size(), get(i)) to the elements of the dat...

Implementing a fixed-size log file, or a circular buffer on disk

I checked this question, but it's not what I'm looking for. I'm trying to figure out how to cap a log file's size (say, 10MB), and as soon as it's hit, either: start writing to the beginning, rather than appending, or keep appending, but delete the contents from the beginning as I do so Don't really care about language - as long as...

Circular buffer pointer irregularities

This is a follow up on this question: Display previously received UART values. After implementing a circular buffer on the microcontroller, it seems that there is a problem with the pointers. Sent on RS-232: ADE1234 Received (buffer = 8): E24AE2 / E2AE24 (Flips between the two) Received (buffer = 16): D234E1 (A is skipped, since it i...

O(1) circular buffer in haskell?

I'm working on a small concept project in Haskell which requires a circular buffer. I've managed to create a buffer using arrays which has O(1) rotation, but of course requires O(N) for insertion/deletion. I've found an implementation using lists which appears to take O(1) for insertion and deletion, but since it maintains a left and rig...

Circular buffer in VB.NET

How can I create a circular buffer on the heap in VB.NET ? This would be used for audio playback via P/Invoke to winmm.dll waveoutopen and waveoutwrite to support development of a software synth. I currently use the marshall class to build a regular array of bytes in the heap. ...

Problem creating a circular buffer in shared memory using Boost

Hi, I am trying to create a circular buffer in shared memory using Boost circular_buffer and Interprocess libraries. I compiled and ran the the example given in the Interprocess documentation for creating a vector in shared memory with no problem. However, when I modify it to use the Boost circular_buffer as: int main(int argc, char *...

What are the uses of circular buffer?

What are some of the uses of circular buffer? What are the benefits of using a circular buffer? is it an alternative to double linked list? ...

How good is the memory mapped Circular Buffer on Wikipedia?

I'm trying to implement a circular buffer in C, and have come across this example on Wikipedia. It looks as if it would provide a really nice interface for anyone reading from the buffer, as reads which wrap around from the end to the beginning of the buffer are handled automatically. So all reads are contiguous. However, I'm a bit unsu...

How do you iterate backward over circular buffer without a conditional?

Iterating forward through a circular buffer without using a conditional is easy with the remainder operator... iterator = (iterator + 1) % buffer_size; I can't for the life of me figure out the reverse operation, iterating backward. ...

How do I code a simple integer circular buffer in C/C++?

I see a lot of templates and complicated data structures for implementing a circular buffer. How do I code a simple integer circular buffer for 5 numbers? I'm thinking in C is the most straightforward? Thanks. ...

Read and write from a file in a circular buffer fashion

Hi, i need to make a file behave as a circular buffer. From one thread i have to write the data.From another thread i have read from the file. But the size of the file is fixed. Any idea? ...

Sharing data array among threads-C++

I know that there are similar questions which are already answered, but I am asking this question since they don’t exactly give what I would like to know. This is about synchronization between threads. The idea of my project is that we obtain data from a data acquisition card and plot and analyze data during data acquisition. So far, I ...

what is called ring in emacs?

Unlike windows style self explanatory copy/cut/paste commands, I could not understand ring concept in emacs. Since I don't program very often in emacs, I could have not realized the value of ring feature. Can you tell me what is called ring in emacs and how to use it? ...

Array wraparound with modulo of unsigned

I'm trying to implement a lagged Fibonacci pseudo-random number generator for integers up to some maximum. It maintains an array of values int values[SIZE] = { /* 55 seed values */ }; and uses the following function to return the next value unsigned lagfib() { static unsigned idx = 0; int r = values[idx]; /* The followin...