Wrapping variables....
Hugh
Posts: 362
Hi,
If I have an array of bytes, such as:
hist[noparse][[/noparse]0] := 1
hist[noparse][[/noparse]1 := 2
hist[noparse][[/noparse]2 := 3
hist[noparse][[/noparse]3 := 4
Is there any simple way I can shift everything 'leftwards' and update the value of hist?
I've tried bitwise shifts to no avail. Should I structure the data differently to enable an easier method?
Any suggestions gratefully received!
Thanks
Hugh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
If I have an array of bytes, such as:
hist[noparse][[/noparse]0] := 1
hist[noparse][[/noparse]1 := 2
hist[noparse][[/noparse]2 := 3
hist[noparse][[/noparse]3 := 4
Is there any simple way I can shift everything 'leftwards' and update the value of hist?
I've tried bitwise shifts to no avail. Should I structure the data differently to enable an easier method?
Any suggestions gratefully received!
Thanks
Hugh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
Comments
-Phil
I think you have the advantage of me w.r.t circular buffers!(?) - the only other way I could think to do it was to copy the earliet to the last and move everything on one: that didn't seem too elegant.
Thanks
Hugh
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
-Phil
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Hugh - the thinking woman's Geoffrey Pyke.
There are a couple of things I'd like to point out:
1) The wiki pages linked to above has examples in C. There they use the mod operator "%" to wrap the head and tail pointers round the buffer. Better to make your buffers a power of 2 in size, 4, 8, 16, 32, 64 etc. Then you can just "and" the head and tail pointers with a mask to wrap them. Much faster.
2) As pointed out above but perhaps not obvious is the fact that one process, in a COG say, can fill the buffer and another can read from the same buffer at the same time with no worries about data corruption when using a cyclic buffer and no locks. But remember only one writer and one reader process is allowed.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
For me, the past is not over yet.