c++ - How much memory does a stack take? -


i'm writing sort algorithm can use stacks. increasing amount of stacks, can sort less operations.

anyway, have dataset of 10 integers. difference in memory following (with std::stack):

  • an array of stacks of size 2 (5 integers per stack)
  • an array of size 10 (1 integer per stack)
  • an array of size 20 (1 integer each in 10 stacks, 10 stacks empty)

also, how memory empty stack of int take? int pointer?

please treat question academic one. know there better ways of solving problem, can use stacks.

the obvious answer is: depends. in reality, there things can said.

all of containers incur modest amount of overhead, of order of (perhaps) couple of pointers , couple of integers, @ most. can find out how if want know, constant , quite small, depending on implementation.

where c++ standard helps places requirements on storage part of container. because iterators (more or less) equivalent pointers, stack elements placed @ consecutive memory locations same alignment array of same items. can predict part.

and lets down again there no limit on amount of 'slack' space. container might contain 5 elements , have enough space 500. again depend on implementation.

so depends. you'll have try , see.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -