Closed zhenhuaw-me closed 6 years ago
Hi @jackwish,
The answer to your question is yes, as std::vector::reserve
only increases the capacity of the vector to the desired amount, but it does not alter the size itself (see https://en.cppreference.com/w/cpp/container/vector/reserve for reference). It is used in that piece of code to prevent unnecessary reallocations for result
.
Since the size that we are reserving for result
is the same as model.operations
, pushing a number of items into result
equal to model.operations.size()
will ensure in both result
and model.operations
have the same size at the end of the loop.
The above link to the documentation also features an example with a similar case (reserve
+ push_back
in a loop).
I hope that helps Regards
cool~
https://github.com/ARM-software/android-nn-driver/blob/deb3bdbe028a59da0759dd7a560387d03a11d322/ArmnnDriver.cpp#L286
result
has reservemodel.operations.size()
before the loop, if we are still pushing toresult
, will the size ofresult
andmodel.operations
be the same?