circular-buffer

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

跟風遠走 提交于 2019-12-03 02:45:35
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. Have an array, buffer , of 5 integers. Have an index ind to the next element. When you add, do buffer[ind] = value; ind = (ind + 1) % 5; Take an array, arr , an index idx , and a counter, num . To insert foo , say arr[idx++] = foo; idx %= buffer_len; num++; . To read out an item into foo , say foo = arr[(idx-num)%buffer_len]; num--; . Add boundary checks. If the size and data type of

Shifting/aligning/rotating a circular buffer to zero in-place

不羁的心 提交于 2019-12-02 20:41:51
I'm using a circular buffer to push data onto either end of a list. After I'm done I want to align the buffer so the first element in the list is at position zero and can be used like a regular array without any fancy indexing overhead. So I have my circular list with capacity N , it has n elements starting at arbitrary index f . What's the fastest way to shift/rotate all the elements such that f = 0 ? The catch is I want to do this in-place (though of course some registers/temporaries will be needed). The buffer may be full ( n = N ), [ EDIT ] but I'm also interested in efficiently handling

Circular Buffer Implementation for FIR Filter in C

半世苍凉 提交于 2019-12-02 16:35:08
问题 I am programming on an embedded microcontroller (TMS320F28069) a 32-bit floating point MCU. I was going over some of the example projects, and one of them implements a simple FIR filter on ADC sampled data. Block diagram here Let's say the ADC buffer has 10 elements. And let's say the filter has length 3 ( FILTER_LEN=3 ). The filter implementation is pretty straightforward, it starts at the end of the delay chain and moves its way to the beginning. float32 ssfir(float32 *x, float32 *a, Uint16

Circular Buffer Implementation for FIR Filter in C

爱⌒轻易说出口 提交于 2019-12-02 08:13:42
I am programming on an embedded microcontroller (TMS320F28069) a 32-bit floating point MCU. I was going over some of the example projects, and one of them implements a simple FIR filter on ADC sampled data. Block diagram here Let's say the ADC buffer has 10 elements. And let's say the filter has length 3 ( FILTER_LEN=3 ). The filter implementation is pretty straightforward, it starts at the end of the delay chain and moves its way to the beginning. float32 ssfir(float32 *x, float32 *a, Uint16 n) { Uint16 i; // general purpose float32 y; // result float32 *xold; // delay line pointer /*** Setup

Search in circular Array

岁酱吖の 提交于 2019-12-02 03:56:10
What is the best way to search in a circular array? Example 1 array : 45 67 44 11 49 4 56 12 39 90 circular array 11, 49, 4, 56, 12, 39, 90, 45, 67 Is Binary search the right approach to start with? Binary search is only useful if the array is sorted. You didn't provide much info about the problem domain but one approach would be to use a set (or hash table). For every number you put in the array, also insert it in the set. Lookups in a set (or hash table) happen in constant time, so there's no "searching". When you remove an item from the array, also remove it from the set. If your circular

boost::circular_buffer equivalent for files?

馋奶兔 提交于 2019-11-30 16:32:18
I am looking for a library which allows to get a circular buffer on disk. In Boost there is something similar, but it is an in memory based container: circular_buffer . You can call it whatever you think is natural. You're looking for memory mapped files. Using the right allocator, you can make containers be allocating in this memory mapped region. That would make the container "on disk". I'll see whether Boost Circularbuffer supports this directly. Update Yes. The best thing is, this gives you full possibility to even use IPC synchronization and thread synchronization. Using a "private"

Circular Buffer in Flash

做~自己de王妃 提交于 2019-11-30 14:02:12
I need to store items of varying length in a circular queue in a flash chip. Each item will have its encapsulation so I can figure out how big it is and where the next item begins. When there are enough items in the buffer, it will wrap to the beginning. What is a good way to store a circular queue in a flash chip? There is a possibility of tens of thousands of items I would like to store. So starting at the beginning and reading to the end of the buffer is not ideal because it will take time to search to the end. Also, because it is circular, I need to be able to distinguish the first item

boost::circular_buffer equivalent for files?

不羁的心 提交于 2019-11-30 00:32:07
问题 I am looking for a library which allows to get a circular buffer on disk. In Boost there is something similar, but it is an in memory based container: circular_buffer. 回答1: You can call it whatever you think is natural. You're looking for memory mapped files. Using the right allocator, you can make containers be allocating in this memory mapped region. That would make the container "on disk". I'll see whether Boost Circularbuffer supports this directly. Update Yes. The best thing is, this

How to implement a circular buffer of cv::Mat objects (OpenCV)?

笑着哭i 提交于 2019-11-29 11:28:20
I'm trying to implement a circular buffer for my program. The buffer is used to share data between two threads as shown below. I use OpenCV to grab video frames from camera (Thread 1). Then I would like to store this data in a circular buffer, so that Thread 2 can get the data from the buffer. How can I implement a circular buffer for cv::Mat objects in c++? I know how to create circular buffer for standard c++ objects (like integer or char) but I can't make it work with objects of type cv::Mat. Any suggestions? Alexey Solved, see Thread safe implementation of circular buffer Whats wrong with

How to read ring buffer within linux kernel space?

◇◆丶佛笑我妖孽 提交于 2019-11-28 16:50:36
问题 I'm writing a Linux character driver which can print system logs in user space. Just as the command 'dmesg' does. I've learned that all the log that we print with 'printk' will be sent to a space named ring buffer. So I have the questions: Is ring buffer inside kernel space? If so, how can I read the ring buffer inside kernel space? (I've tried to read the source code of dmesg.c. But it did not help.) 回答1: What you are looking for is /proc/kmsg . This is the kernel ring buffer! Yes, this is