I have the following scenario: a variable number of elements, let’s say from 100 to 1500, and this number fluctuates with each iteration. These elements are swapped between 2 buffers, each preallocated with space for 2000 elements. Buffers should
- allow to set their size explicitly (if number of elements < 2000, no allocation, if bigger, grow and allocate a bigger chunk of memory).
- allow to sequentially fill them with
push!
, which affects only theirlength()
property, if the size of the buffer is not exceeded.
Questions:
- What data structure should I use for these buffers in Julia?
Vector{T}
seems to be not sufficient, but I may be wrong. - What
empty!()
does to let’s saybuff = Vector{E}(2000); empty!(buff)
- is all allocated memory returned to the system, or, when, after emptying, we dopush!(buff, E())
it reuses the allocated block(2000 * sizeof(E))
of memory?
I would highly appreciate any piece of advice here.