From: aslan on 7 Dec 2009 04:12 "Ulrich Eckhardt" <eckhardt(a)satorlaser.com>, iletisinde şunu yazdı, news:frruu6-h0d.ln1(a)satorlaser.homedns.org... > aslan wrote: >> "Tim Roberts" <timr(a)probo.com>, iletisinde sunu yazdi, >>> Yes, but you are conveniently and repeatedly ignoring the most important >>> point. "std::vector<bool> a" is NOT the same as "bool a[32]". There is >>> an special optimization allowed for std::vectors of bool, which allows >>> them to be packed 8 to a byte. That CANNOT be done for "bool a[32]". >>> For example, this is legal: >>> >>> std::vector<int> vi; >>> vi.resize(32); >>> int * pi = &vi[0]; >>> >>> After this, pi will point to a 128-byte piece of memory, with room for >>> 32 >>> ints. But when you do this: >>> >>> std::vector<bool> vb; >>> vb.resize(32); >>> bool * pb = &vb[0]; >>> >> No Sir, >> I have tried it and I don't get any compile or run-time error with SGI >> STL >> on my machine. > > The STL is not standard C++. You can install it, but if you then rely on > things where it differs from the C++ standard library, you get exactly > what > you got. Let me repeat that: The STL, as far as the C++ standard is > concerned is just a library. Since it also puts symbols into the 'std' > namespace, it could even be called a bad library, as that namespace is > reserved. > > Aslan, why are you using the STL anyway? Development of it was abandoned > more than half a decade ago. Most parts of it have been incorporated into > the C++ standard (which is probably the reason many people confuse the > two), so they are available in a standard-conformant way there. I see no > reason to use the STL in modern code. > > Uli > 6 or 7 years ago, I was developing some code using STL and VC++ 6 (I still use it mostly due to my job requirements) and I had some problems with MS STL and decided to give a try to SGI STL and was satisfied with it. So I still use it. For my pesonal projects also I still use VC++ 6 and STL combo. It was recently that I tried to compile a program using VC++ 2005 EE to see if I could get any speed improvement. Well I could port it VC++ 2005 EE using the suggestions I received in this thread but there was no speed improvement even it was slightly slower. > -- > C++ FAQ: http://parashift.com/c++-faq-lite > > Sator Laser GmbH > Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
From: aslan on 7 Dec 2009 04:41 "Tim Roberts" <timr(a)probo.com>, iletisinde sunu yazdi, news:a8gmh5laf2ml7igh6besbtc10d5v67qhs4(a)4ax.com... > "aslan" <aslanski2002(a)yahoo.com> wrote: >> >>OK. Tim Roberts was talking about MS STL implementation whereas I use SGI >>STL implementation so I didn't notice it then. > > I'm not convinced. The STL implementation in VC++6 was written by PJ > Plauger and contains HP's copyright. HP and SGI cooperated on STL. I guess SGI's is based on HP's but with additions and modifications by SGI. Copyright � 1996-1999 Silicon Graphics Computer Systems, Inc. Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Silicon Graphics makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. Copyright � 1994 Hewlett-Packard Company Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Hewlett-Packard Company makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. > > Here's a way to tell. Try to compile this: > > std::vector<bool> vb; > vb.resize(32); > bool * pb = &vb[0]; > > If that compiles, then your implementation of STL does not have this > optimization, and the vector probably occupies 32 bytes. If that gets a > compile-time error, then your STL has the same optimization as > Microsoft's, > and the vector occupies 4 bytes. > -- > Tim Roberts, timr(a)probo.com > Providenza & Boekelheide, Inc.
From: aslan on 7 Dec 2009 05:29 "Tim Roberts" <timr(a)probo.com>, iletisinde sunu yazdi, news:a8gmh5laf2ml7igh6besbtc10d5v67qhs4(a)4ax.com... > "aslan" <aslanski2002(a)yahoo.com> wrote: >> >>OK. Tim Roberts was talking about MS STL implementation whereas I use SGI >>STL implementation so I didn't notice it then. > > I'm not convinced. The STL implementation in VC++6 was written by PJ > Plauger and contains HP's copyright. HP and SGI cooperated on STL. > > Here's a way to tell. Try to compile this: > > std::vector<bool> vb; > vb.resize(32); > bool * pb = &vb[0]; > > If that compiles, then your implementation of STL does not have this > optimization, and the vector probably occupies 32 bytes. If that gets a > compile-time error, then your STL has the same optimization as > Microsoft's, > and the vector occupies 4 bytes. > -- > Tim Roberts, timr(a)probo.com > Providenza & Boekelheide, Inc. I have found the following in the SGI's documentation. See the warning: bit_vector Category: containers Component type: type Description A bit_vector is essentially a vector<bool>: it is a Sequence that has the same interface as vector. The main difference is that bit_vector is optimized for space efficiency. A vector always requires at least one byte per element, but a bit_vector only requires one bit per element. Warning: The name bit_vector will be removed in a future release of the STL. The only reason that bit_vector is a separate class, instead of a template specialization of vector<bool>, is that this would require partial specialization of templates. On compilers that support partial specialization, bit_vector is a specialization of vector<bool>. The name bit_vector is a typedef. This typedef is not defined in the C++ standard, and is retained only for backward compatibility. Example bit_vector V(5); V[0] = true; V[1] = false; V[2] = false; V[3] = true; V[4] = false; for (bit_vector::iterator i = V.begin(); i < V.end(); ++i) cout << (*i ? '1' : '0'); cout << endl; Definition Defined in the standard header vector, and in the nonstandard backward-compatibility header bvector.h.
From: Ulrich Eckhardt on 7 Dec 2009 07:42 Tim Roberts wrote: > "aslan" <aslanski2002(a)yahoo.com> wrote: >> >>OK. Tim Roberts was talking about MS STL implementation whereas I use SGI >>STL implementation so I didn't notice it then. > > I'm not convinced. The STL implementation in VC++6 was written by PJ > Plauger and contains HP's copyright. HP and SGI cooperated on STL. > > Here's a way to tell. Try to compile this: > > std::vector<bool> vb; > vb.resize(32); > bool * pb = &vb[0]; > > If that compiles, then your implementation of STL does not have this > optimization, and the vector probably occupies 32 bytes. If that gets a > compile-time error, then your STL has the same optimization as > Microsoft's, and the vector occupies 4 bytes. Just to put that into historic context: The STL doesn't have a specialisation of vector<bool>. In the STL, vector<bool> behaves just like any other vector. What it does have is a vector-like container (bit_vector) that operates on a sequence of bits. Now, the C++ standard library does require a specialisation for std::vector<bool> and that it behave (more or less) like STL's bit_vector. I seem to remember a class being part of the standard that actually stored bool objects like a vector, i.e. which then behaves like STL's vector<bool> again, but I'm not sure about that. In any case, talking about different STLs and meaning different implementations of the C++ standard library is what only adds to the confusion. They are not the same and not even interchangeable, e.g. the STL doesn't include IOStreams, which form a major part of the C++ standard library. Uli -- C++ FAQ: http://parashift.com/c++-faq-lite Sator Laser GmbH Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
First
|
Prev
|
Pages: 1 2 3 4 5 6 Prev: Owner drawn listbox problem Next: Changing file attributes, Windows Explorer way. |