Thread overview | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
December 20, 2013 Circular Buffer | ||||
---|---|---|---|---|
| ||||
I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijack the code and modify only what is needed rather than duplicate a lot of stuff? (or maybe someone could just add it to the library... circular arrays are useful ya know ;) |
December 20, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | There's actually already a circular buffer implemented in vibe.d, and if I remember right it's not dependent on anything from vibe.
On 12/20/13, Frustrated <c1514843@drdrb.com> wrote:
> I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijack the code and modify only what is needed rather than duplicate a lot of stuff? (or maybe someone could just add it to the library... circular arrays are useful ya know ;)
>
>
|
December 20, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Orvid King | But does it rely on the GC? |
December 20, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | Frustrated:
> I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC.
Why do you need to avoid the GC?
Bye,
bearophile
|
December 20, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | On 12/20/2013 04:45 PM, Frustrated wrote:
> I'm in need of a circular buffer/array. I am using std.container.array
> to avoid the GC. I suppose I could copy and modify the code but is there
> any easier way? ...
What prevents you from implementing your buffer using an std.container.Array as the backing store?
|
December 20, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | On 12/20/13, Frustrated <c1514843@drdrb.com> wrote: > But does it rely on the GC? > Nope, the template you wanted is vibe.utils.array:FixedRingBuffer. |
December 20, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | Use std.range.cycle with std.container.Array (slice the array to get a range). http://dlang.org/phobos/std_range.html#.cycle |
December 21, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | On Friday, 20 December 2013 at 15:45:04 UTC, Frustrated wrote: > I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijack the code and modify only what is needed rather than duplicate a lot of stuff? (or maybe someone could just add it to the library... circular arrays are useful ya know ;) http://p0nce.github.io/gfm/gfm.core.queue.html#RingBuffer < and use malloc instead of .length |
December 21, 2013 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to Frustrated | On Friday, 20 December 2013 at 15:45:04 UTC, Frustrated wrote: > I'm in need of a circular buffer/array. I am using std.container.array to avoid the GC. I suppose I could copy and modify the code but is there any easier way? It looks like it is defined as templates so could I somehow hijack the code and modify only what is needed rather than duplicate a lot of stuff? (or maybe someone could just add it to the library... circular arrays are useful ya know ;) Writing your own should be quite simple. I see others have already added some implementations, so I'll add mine too. Modifying it to use a static array shouldn't be too difficult, but you're probably better off using some of the others code as this is dynamic and haven't been used in production. https://gist.github.com/simendsjo/3b8a9c60bd92e16691d7 |
February 10, 2014 Re: Circular Buffer | ||||
---|---|---|---|---|
| ||||
Posted in reply to lomereiter | (disclaimer: I'm new around here) Is it possible to cycle backwards? If not, what's the best approach? Example of some ideal "takeBack" function: data = cycle([1,2,3][]) take(data, 4) is [1,2,3,1][] takeBack(data, 4) would be [1,3,2,1][] Thoughts? |
Copyright © 1999-2021 by the D Language Foundation