Open dselivanov opened 5 years ago
In PriorityQueue, the memory is first pre-allocated and the memory is reallocated and doubled if we hit the memory cap. While it's a bit memory inefficient, but we trade memory for speed. We may also implement this expanding memory idea to List.
https://github.com/randy3k/collections/blob/master/src/priorityqueue.c#L18
I think it may make sense to create a wrapper around R's list with clear
append
semantics without copy of the object. Recently R lists (and actually arrays) seems improved a lot in a sense that they don't make copies with each append. But this is not widely known.As can be seen it is still better to pre-allocate result, but dynamic resizing is not that bad now (few re-allocations).