Topic: vector will be contiguous (Was: variable length arrays in C++ (was: Re


Author: scorp@btinternet.com (Dave Harris)
Date: 1999/08/04
Raw View
pjp@plauger.com (P.J. Plauger) wrote:
> No, I haven't written about it yet. But my Java version of vector
> is a circular buffer, and I find I use it in most places where one
> would normally use the much more complex deque. The main
> thing it gets you is push_front and push_back both work in
> constant time if there's any reserve storage at all.

Of course, in Java contiguity doesn't bring so many advantages because the
language doesn't have user-defined value types or PODs. You can't have an
array of POINT that you can pass directly to Win32's Polygon() routine,
for example; only an array of references to POINT.

Must std::deque be so complex? Can't it be implemented as a plain circular
buffer or ring-buffer? It seems to me that the vector and deque have
massively different implementations, and this has more to do with
approaches to resizing than to the differences in their interface. The
names don't really capture what is going on.

  Dave Harris, Nottingham, UK | "Weave a circle round him thrice,
      brangdon@cix.co.uk      |   And close your eyes with holy dread,
                              |  For he on honey dew hath fed
 http://www.bhresearch.co.uk/ |   And drunk the milk of Paradise."
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]