circular-buffer

Circular buffer in flash implementation

丶灬走出姿态 提交于 2019-12-11 16:43:04
问题 I have been working on data logger for an embedded device. The goal is to store values of a set of variables in periodic manner into the external flash memory. My idea is to create a buffer in RAM. Size of the buffer will be equal to the number of bytes in one sector in the external flash i.e. 512 B. After expiration of prescribed time I will fill the buffer with values of the variables and then I will store this record into the external flash. External flash contains several blocks reserved

C++ how to mix a map with a circular buffer?

江枫思渺然 提交于 2019-12-10 17:38:47
问题 I wonder is it possible to have a map that would work like boost circular buffer. Meaning it would have limited size and when it would get to its limited size it will start overwriting first inserted elements. Also I want to be capable to search thru such buffer and find or create with [name] . Is It possible to create such thing and how to do it? 回答1: Well, I don't think that structure is present out of the box in boost (may exist elsewhere, though), so you should create it. I wouldn't

Windows ring buffer without copying

眉间皱痕 提交于 2019-12-09 18:25:26
问题 On Ring Buffer's Wikipedia entry, there's example code showing a hack for UNIX systems whereby the adjacent virtual memory to a piece of memory is mapped to the same phbysical memory, thus implementing a ring buffer without the need for any memcpy, etc. I was wondering if there's a way to so something similar in Windows? Thanks, Fraser 回答1: I didn't really follow all the details of the example in wikipedia. With that in mind, you map memory in Windows using CreateFileMapping and MapViewOfFile

scala collections circular buffer

我只是一个虾纸丫 提交于 2019-12-09 11:42:47
问题 Just messing about here, with circular buffers. Is this a sensible implementation or is there a faster/more reliable way to skin this cat? class CircularBuffer[T](size: Int)(implicit mf: Manifest[T]) { private val arr = new scala.collection.mutable.ArrayBuffer[T]() private var cursor = 0 val monitor = new ReentrantReadWriteLock() def push(value: T) { monitor.writeLock().lock() try { arr(cursor) = value cursor += 1 cursor %= size } finally { monitor.writeLock().unlock() } } def getAll: Array[T

Creating a Generic Circular Buffer

折月煮酒 提交于 2019-12-07 07:13:14
问题 Given the desire to abstract the structure of a circular buffer from its content, and starting from the following code segments (courtesy of this wikipedia entry): typedef struct { int value; } ElemType; typedef struct { int size; /* total number of elements */ int start; /* index of oldest element */ int count; /* index at which to write new element */ ElemType *elements; /* vector of elements */ } CircularBuffer; void cbInit(CircularBuffer *cb, int size) { cb->size = size; cb->start = 0; cb

C /C++ Lock-free (or nonblocking) Ring Buffer that OVERWRITES oldest data?

别来无恙 提交于 2019-12-06 22:32:31
问题 I'm trying to find a way to make a Lock Free OR Non-blocking way to make a Ring Buffer for single consumer / single consumer that will over-write the oldest data int the buffer. I've read a lot of lock-free algorithms that work when you "return false" if the buffer is full--ie, don't add; but I can't find even pseudo-code that talks about how to do it when you need to overwrite the oldest data. I am using GCC 4.1.2 (restriction at work, i can't upgrade the version...) and I have the Boost

Queue implementation with circular arrays: Which is the best way to resize a circular array?

时光怂恿深爱的人放手 提交于 2019-12-06 01:57:50
I'm implementing a queue using a circular array , and I'm kind of stuck in the resize() method implementation (when the array is full). Inside the enqueue() method I check if the size of the array equals it's length, and get if it's full. Now, instead of throwing an exception, I'm trying to resize the array. The thing is, I have two cases to consider front <= rear rear < front Which is the best way to copy the elements of the old array into the new, larger one? I thought it using a for-loop, like: newArray = new Array[oldArray.length*2]; if (front <= rear) { for (int i = front; i < rear; i++)

a text file circular buffer in python

折月煮酒 提交于 2019-12-06 00:34:52
问题 I need a python script implementing a circular buffer for rows in a text file limited to N rows like this: row 1 -> pop row 2 row 3 | | push -> row N What's the best solution? EDIT: This script should create and maintain the text file which only contains the latest N lines. Then it should pop the first line pushed in. Like a fifo buffer. 回答1: Try my recipe and sorry for italian usage: #!/usr/bin/env python # -*- coding: utf-8 -*- # # fifo(.py) # # Copyright 2011 Fabio Di Bernardini <fdb

Creating a Generic Circular Buffer

拟墨画扇 提交于 2019-12-05 17:03:13
Given the desire to abstract the structure of a circular buffer from its content, and starting from the following code segments (courtesy of this wikipedia entry): typedef struct { int value; } ElemType; typedef struct { int size; /* total number of elements */ int start; /* index of oldest element */ int count; /* index at which to write new element */ ElemType *elements; /* vector of elements */ } CircularBuffer; void cbInit(CircularBuffer *cb, int size) { cb->size = size; cb->start = 0; cb->count = 0; cb->elements = (ElemType *)calloc(cb->size, sizeof(ElemType)); } How does one abstract the

Simplified algorithm for calculating remaining space in a circular buffer?

♀尐吖头ヾ 提交于 2019-12-05 08:11:32
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; If you're worried about poorly-predicted conditionals slowing down your CPU's pipeline, you could use this: int remaining = (end - start) + (-((int) (end <= start)) & bufferSize); But that's likely to be premature optimisation (unless you have really identified this as a hotspot). Stick with your current technique, which is much more readable. Hmmm.... int remaining = (end - start + bufferSize) % bufferSize; 13