Re: Use of std::vector slower than arrays?
On Nov 13, 6:20 pm, Erik Wikstr=F6m <Erik-wikst...@telia.com> wrote:
On 2007-11-13 12:32, James Kanze wrote:
On Nov 13, 3:49 am, "Jim Langston" <tazmas...@rocketmail.com> wrote:
"mike3" <mike4...@yahoo.com> wrote in message
news:1194910849.305759.249510@z24g2000prh.googlegroups.com...
[...]
And VC++ deserves an accolade, both for the quality of its
library and the quality of its compiler. And a criticism: I had
to grunge around in the sources to find the _SECURE_SCL define;
while it didn't take me more than a couple of minutes, that's
because I'm used to this sort of thing---it really should be
documented somewhere. (Maybe it is, but I don't know how to
find it.)
It is quite well documented if you know where to look (search
for checked iterators at msdn), the problem is that they do
not tell you about it on the pages describing the containers
and iterators.
The problem is that it isn't documented with the rest of the
compiler flags controling optimization. I know the reason, and
I know that Microsoft isn't alone in this; the reason I was able
to find it so quickly perusing the sources is because I've had
to do the same thing so often with other compilers. (Where does
g++ document -D_GLIBCXX_DEBUG, etc., for example.)
Such documentation belongs on the page with the compiler code
generation options. (Even better, of course, would be to add a
real option to the compiler driver, which defines the symbol one
way or another.)
Of course, if you want any real speed for this, you'll rewrite
the inner loop in assembler, where you have direct access to the
carry flag (and an add instruction which takes it into account,
so you don't have to test it anyway).
MS would recommend to use intrinsics (SIMD instructions) but
of course by then you have left everything called portability
behind. And I have no idea whether they would be useful for
this purpose.
Once you use assembler, you've abandonned portability. But some
things (like the handling of carry) can't be easily expressed in
C++, and yet are simple in assembler. (I once saw 2000 lines of
C, used for BCD arithmetic, rewritten in something like 40 lines
of assembler. In this case, the assembler was actually "higher
level" than C, since the target machine had hardware
instructions which did almost exactly what we needed. Of
course, the resulting assembler only worked on that one
machine.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34