Archived

This topic is now archived and is closed to further replies.

Greg K

STL Overhead

Recommended Posts

How much overhead does a STL stack have? Is it a bad idea to use them alot? For instance I could either have a void*, allocate mem for my object, and then insert the data. Or I could use a stack for this particular problem. I would have a very large number of these objects all at one time (possibly hundreds) so is it a bad idea to use STL stacks or is there hardly any overhead? -Greg Koreman

Share this post


Link to post
Share on other sites
the STL offers extremely high performance with minimal overhead. Plus, it''s standard. So it''s portable.

bottom line: use it. you won''t be sorry.

Share this post


Link to post
Share on other sites
quote:
Original post by Greg K
How much overhead does a STL stack have?

Compared to what? An STL stack contains no more cruft than a very well-designed non-STL stack.

Share this post


Link to post
Share on other sites
The STL is incredibly fast.

But you should always implement your own allocators, especially if you work with MSVC++ where heap allocation takes way too much time.

Share this post


Link to post
Share on other sites
Yup yup.

You should waste your time writing new allocators without determining if they''re bottlenecking you, because that''s a great way to spend your time.

@_@.

Share this post


Link to post
Share on other sites
quote:
Original post by DrPizza
Yup yup.

You should waste your time writing new allocators without determining if they''re bottlenecking you, because that''s a great way to spend your time.

@_@.



LOL

Premature Optimization is the Dark Side of programming. Always a strong temptation, but never worth it.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Original post by DrPizza
Yup yup.

You should waste your time writing new allocators without determining if they''re bottlenecking you, because that''s a great way to spend your time.

@_@.



I''ll point out that when STL pops off an objet, it doesn''t release that memory, it is returned to a pool for STL to use later.

Just make sure that you aren''t allocating/deallocating on the heap while runtime performance is critical.



Share this post


Link to post
Share on other sites
It really depends on the type of container used in the stack

By default, it''s a std::deque, which actually shrinks when you pop objects off the top.

Share this post


Link to post
Share on other sites
quote:
Original post by daerid
By default, it''s a std::deque, which actually shrinks when you pop objects off the top.


No it doesn''t. deques are normally implemented by a vector of pointers to blocks of objects (notionally, at least).

As you fill the deque, it fills up a block, and adds new blocks only as necessary.

If you take an item from the deque, there''s no shrinking until and unless you empty an entire block; even then, I suspect the shrinkage would be up to the implementation to perform.

Share this post


Link to post
Share on other sites