I'm recording some statistics in my application. One of the statistics is the size of BigDataStructure. I have two options:
Create a counter and increment / decrement the counter each time there is an add/remove from the BigDataStructure.
Each time there is an add/remove from the BigDataStructure, set the counter to BigDataStructure.size().
Is there a good argument for doing it one way or another? Incrementing / decrementing the counter myself avoids a call to BigDataStructure.size(). It also doesn't directly involve the assignment operator (although maybe it does under the hood?)
Given these two options, which one is preferable?