Archived

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

STL Overhead

This topic is 5594 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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
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