Ah, yes, sure, but that was not my motivation. I guess my benchmarks 
obscured my goals here. My original benchmarks had a loop like the one you 
write first, followed by a resize!(a, 0), followed by another loop (of the 
kinds in my benchmarks above). That reflects more closely my application. 
That is, I'll be adding elements and then resetting the array repeatedly – 
and these benchmarks were designed to look at what happens after such a 
resize if I either actually use resize!(…) or if I just keep the array, and 
manually manage a size variable so I know which parts of it are viable.

I was originally looking for a way of doing the latter with less "manual" 
work – but was surprised to find that the version with push! seems to be 
faster than simple assignment, oddly enough. Not sure what's going on, 
really.

As for the size hint, I don't really know that when I start, so it's not 
really that useful in my case.

Sorry for the misleading benchmark code – hope this clarified things a bit.

Reply via email to