According to the Microsoft documentation, calling Clear() on a List is an O(n) operation. I'm guessing this is because if the list were to hold references, it would need to null them. I was wondering if Clear() is still an O(n) operation if the list has value types, since the capacity is not changed. Shouldn't it be enough to reset the index pointer and count?
I'm asking this because in a current application we're using lists that get cleared hundreds of thousands of times in a very short time span, and wanted to know if there could be a different implementation that makes it faster.
Aucun commentaire:
Enregistrer un commentaire