I want to append the raw bytes into vector like this.
vector.reserve(current_size + append_data_size);
memcpy(append_data, vector.data() + current_size, append_data_size);
vector.resize(current_size + append_data_size) // Expect only set size to current_size + append_data_size.
does below is slower? because I think vector is initialised to default first then set the data which is waste.
vector.resize(current_size + append_data_size);
memcpy(append_data, vector.data() + current_size, append_data_size);
resizeenlarges a vector, it creates new values (even if there is already space for them). Thereserveoperation just makes space.vector.insert(iter_pos_into_vec, start_of_range_to_copy, end_of_range_to_copy)memcmp()for that!? Also, what isn? Why wouldn + 100become100?memcpy(). That is exactly why you're required to provide a minimal reproducible example, btw. It avoids code that doesn't compile and doesn't work, thus obfuscating the question.