Boost logo

Boost Users :

From: hicks (hicks_at_[hidden])
Date: 2001-12-01 10:41:45


Hello

I have a problem with the standard ways in which std::vector
behaves when it destructs or reallocates.

I want to make this explanation short so I will skip details.
In a nutshell, during destruction or resize, a destructor
is explicitly called from a loop for each element which has
been constructed. Obviously this is desireable much of the time,
but it is true even if the element type has an *empty* destructor.
This can take a lot of unecessary time, like 10's or even a few 100
milliseconds, which can make a big difference in, say, inspection
software used in an industrial production line.

Contrast this with the behavior of "delete[]".
"delete[]" is smart enough not to execute anything when the
destructor body of its elements is empty.

I wrote a replacement vector class which uses delete[] internally but
otherwise acts like std::vector just to get around this problem.
There are some drawbacks and limitations during resizing, but
there are times when this behavior is essential.

Unfortunately, containers like the graph boost library use std::vector
as containers and that is hardcoded. So the destructor for a graph might
take 100 or 200 ms, when it should take almost nothing because there is
nothing dangerous which really needs to be cleaned up.

I am interested if anyone has faced the same situation and has any
advice or thoughts
about it. This seems like a general limitation of the stl, so I thought
it would
be suitable for discussion here.

Several months ago I tried to explain the same thing but the wording was
obtuse and I got off
to a bad start. So now I try again.

Craig Hicks
Engineer KGK Tokyo


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net