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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -