Boost logo

Boost :

From: Christoph Koegl (yahoo_at_[hidden])
Date: 2001-02-19 10:50:28


Hi Craig.

You need to be more specific in your question. What is it you want to do? Which
operations do you need and which ones need to be efficient as possible? Perhaps
an std::vector is not the right data structure or container at all.
What do you mean by "std::vector always initialized all the elements on
resize()"? All the new elements? All elements in the vector? All elements in
the vector or reallocation (which happens if during an insert or an push_back
or whatever operation the underlying vector memory is exhausted)? No class
or structure has "no constructors", as you say, some just happen to have only
a standard default constructor (plus a copy constructor), but these might be
protected/private; for use in an std::vector the element type must be default
constructible and assignable (hence must have a public default ctor and a public
copy ctor). If the default ctor is the standard one (which a class/struct has
if there is none specified in the class/struct definition) and if some type
traits class is used (as is internally in SGI's STL or in STLport for speciali-
zations of some templated functions that benefit from trivial-ness of default
ctor, copy ctor, or dtor) and if your compiler loves you, no code for
initializing std::vector elements is generated, hence no overhead. What do you
mean by "Using push_back() would could a size check on each access"? There is
no std::vector bounds check, but reallocation of the underlying memory might be
triggered. Is it this that you mean? What is it you mean to say when you ask
"if perhaps there is an easy (no more than say 1 line of code) to make
std::vector do the same thing"? Which "same thing"?
Perhaps you could show us some code of yours to illustrate what you want to do.
As I am relatively new to this list, I am not sure how relevant to the boost
libraries this request is at all, so you might want to contact me by private
e-mail.

Cheers, Christoph

-- 
================================================================================
Christoph Koegl, Dept. of Computer Science, University of Kaiserslautern
E-Mail: christoph_at_[hidden]             WWW: http://www.familie-koegl.de/
--------------------------------------------------------------------------------
There are no stupid questions, but there are a LOT of inquisitive idiots.
--------------------------------------------------------------------------------

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk