Merged
Conversation
Owner
|
Hi there, thanks for this! I think it depends slightly because the type of the vector depends on the class template type T, which is very very likely to be a float or double, or an integer of some type, but in theory one could use it with a different parameter for T (as long as that parameter fulfilled the requirements for being assigned values etc). Perhaps the cleaner way to do this is to use the second parameter of resize? I.e. samples[i].resize (numSamples, static_cast (0)); just to explicitly make clear we want to zero-initialise any new samples? |
e5eb963 to
30bbc55
Compare
Contributor
Author
|
@adamstark Fixed Despite my initial assumption default-init would be faster because of memset, benchmarking your method showed no difference. |
std::vector::resize already zeroes the new samples, so we don't need to use std::fill. See https://stackoverflow.com/a/73333009/10477326 However, we pass a second parameter to explicitly copy-init with zero and to not default-init. Benchmarks showed the performance difference between the two to be statistically insignificant, despite default-init having memset.
30bbc55 to
3d5f585
Compare
Owner
|
Thanks for this! Merging in now... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
std::vector::resizealready zeroes the new samples, so we don't need to usestd::fill. See https://stackoverflow.com/a/73333009/10477326However, we pass a second parameter to explicitly copy-init with zero
and to not default-init. Benchmarks showed the performance difference
between the two to be statistically insignificant, despite default-init
having memset.