Buffer for CircularDeque

Good day folks of Julialand!

If I have something similar to the following

function foo(x)
   w = 50
   d = CircularDeque{Int64}(w)
   # Do some calculation based on x using d and return the result
end

for i in 1:1000000
   out[i] = foo(x[i])
end

In this case, the memory for d is allocated a million times. Not good! I could pass d into foo() and manipulate it in place to avoid this. However, if I do this then d will not start out as a “fresh” Cicular Deque without values in it.

Is there any convenient way to pass some of the memory buffer for the circular deque to foo()?

Thanks!

read the documentation CircularDeque · DataStructures.jl the answer is there :wink:

Also your code in not a runnable MWE, please see Please read: make it easier to help you - #81

Sorry for no MWE. I didn’t consider it important in this case.

I don’t see the answer to my question in the documentation. Could you further specify a little?

Alright. Passing one circular deque to the function and then using the empty!() function after each run seems to do the trick. Sadly it actually worsened performance of my specific case but that is another question. :slight_smile:

Sorry. That is what I had in mind. So sad.

If u did provide mwe then I could’ve tested that.

1 Like