c# - Stack constructor - What to put as initial capacity? -
one of constructors shown on msdn, takes int32
parameter representing initial capacity.
there remark on above documentation page states following:
if count less capacity of stack, push o(1) operation. if capacity needs increased accommodate new element, push becomes o(n) operation, n count. pop o(1) operation.
i'm in situation don't know how initial capacity give stack. better overestimate think need ? because surely low initial capacity make performance suffer?
what drawback in passing in high initial capacity in terms of performance?
internally, storage array inside stack<t>
grows exponentially, implies amortized o(1) cost add element. so, if don't know correct initial capacity, don't worry , use default constructor, performance anyway.
Comments
Post a Comment