Re: disadvantages of using STL
On Mar 17, 8:53 pm, c...@mailvault.com wrote:
On Mar 17, 3:44 pm, Pallav singh <singh.pal...@gmail.com> wrote:
On Mar 18, 1:36 am, Victor Bazarov <v.Abaza...@comAcast.net> wrote:> =
Pallav singh wrote:
Q What are the disadvantages of using STL ?
There's a nice table comparing intrusive and non-intrusive containers
in these
pages:http://www.boost.org/doc/libs/1_38_0/doc/html/intrusive/.
Table 10.1. Summary of intrusive containers advantages and
disadvantages
Issue Intr=
usive Non-intrusive --
STL
-------------------------------------------------------------------------=
-----------
Memory management External =
Internal through
allocator
Insertion/Erasure time Faster =
Slower
Memory locality Better =
Worse
Can hold non-copyable and Yes =
No
non-movable objects by value
Exception guarantees Better =
Worse
Computation of iterator from value Constant Non-const=
ant
Insertion/erasure predictability High Low
Memory use Minimal =
More than
minimal
Insert objects by value retaining Yes N=
o (slicing)
polymorphic behavior
User must modify the definition of Yes No
the values to insert.
Containers are copyable No =
Yes
As far as I can tell what is listed in this table is accurate,
but it seems like one thing is missing that in my opinion is
in favor of non-intrusive containers. There's no measurement
of access times of elements. For example, by dereferncing a
std::list<int> iterator you get right to the value you want.
But with an intrusive list you have something like:
struct MyClass : list_base_hook<>
{
int a_;
};
boost::intrusive::list<MyClass> intrsv_lst;
boost::intrusive::list<MyClass>::iterator it;
Now you have to go through the object first to get to
the int member. So while the table mentions that
insertion/erasure is faster with an intrusive
container, it doesn't say anything about access times.
I'm not really inclined to convert STL containers of
either a basic type or a pointer to a base type to
intrusive containers. The intrusive syntax is
clumsier and the accesses will be a little slower.
But if you have a container of user defined types it
makes more sense to me to use an intrusive container.
Brian Wood
Ebenezer Enterprises
www.webEbenezer.net