Skip to content
Advertisement

Initialize deque efficiently

I am using a deque to store data that is going to be processed. The processing only starts when the deque is full so in a first step I fill my buffer the following way:

JavaScript

However, when I do this and I modify one of the elements of my_deque, all elements of my_deque are modified.

One alternative I found to avoid this issue is to initialize my deque the following way

JavaScript

Is there a more elegant way to achieve this?

Edit: One example of modification that create the issue is the following

JavaScript

After this line of code, the third row of every element of my_deque is a row of zeros, not just the one at index 7

Advertisement

Answer

@MichaelSzczesny’s comment was the right answer, it seems to have been deleted so I post it here:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement