From: Tim K. <tim...@ce...> - 2008-09-26 12:42:22
|
Dear all, Parallel::max() (and other parallel functions) assume, when a vector is supplied, that std::vector stores all its elements consecutively. Does the STL guarantee that this is true, or is this just an assumption that you make? (I'm asking because I need to do some things like this an a context without libMesh, and I have dealt a lot with converting a std::vector to a C array in earlier times because I was unable to find a piece of information that guarantees that I can safely to what you are doing.) Best Regards, Tim -- Dr. Tim Kroeger Phone +49-421-218-7710 tim...@me..., tim...@ce... Fax +49-421-218-4236 MeVis Research GmbH, Universitaetsallee 29, 28359 Bremen, Germany Amtsgericht Bremen HRB 16222 Geschaeftsfuehrer: Prof. Dr. H.-O. Peitgen |
From: Roy S. <roy...@ic...> - 2008-09-26 13:18:52
|
On Fri, 26 Sep 2008, Tim Kroeger wrote: > Parallel::max() (and other parallel functions) assume, when a vector > is supplied, that std::vector stores all its elements consecutively. > Does the STL guarantee that this is true, >From what I've read, as of 2003, it's guaranteed in the standard to be true, but even before that nobody had ever heard of a compiler doing it differently. > (I'm asking because I need to do some things like this an a context > without libMesh, and I have dealt a lot with converting a std::vector > to a C array in earlier times because I was unable to find a piece of > information that guarantees that I can safely to what you are doing.) The only big catch that you need to worry about with that conversion is vector resizing - when the STL says that an operation might invalidate an iterator, that basically translates as "might make us move the whole underlying array somewhere else in memory". --- Roy |
From: Roy S. <roy...@ic...> - 2008-09-26 13:19:01
|
On Fri, 26 Sep 2008, Roy Stogner wrote: > The only big catch that you need to worry about with that conversion > is vector resizing Whoops! There's actually one more catch, if you have an expansive definition of "C array". To save storage space, there's a trick in the standard: std::vector<bool> isn't really a std::vector, it's a data structure that encapsulates some bit twiddling to carry the requested information. Even trying to get a reference to a single bool entry isn't supported AFAIK, much less trying to do pointer arithmetic on them. --- Roy |
From: Tim K. <tim...@ce...> - 2008-09-26 13:29:18
|
Dear Roy, On Fri, 26 Sep 2008, Roy Stogner wrote: >> The only big catch that you need to worry about with that conversion >> is vector resizing > > Whoops! There's actually one more catch, if you have an expansive > definition of "C array". To save storage space, there's a trick in > the standard: std::vector<bool> isn't really a std::vector, it's a > data structure that encapsulates some bit twiddling to carry the > requested information. Thank you very much for you reply. Where on the internet can I find that document that says all there things? Best Regards, Tim -- Dr. Tim Kroeger Phone +49-421-218-7710 tim...@me..., tim...@ce... Fax +49-421-218-4236 MeVis Research GmbH, Universitaetsallee 29, 28359 Bremen, Germany Amtsgericht Bremen HRB 16222 Geschaeftsfuehrer: Prof. Dr. H.-O. Peitgen |
From: John P. <jwp...@gm...> - 2008-09-26 13:47:56
|
On Fri, Sep 26, 2008 at 8:28 AM, Tim Kroeger <tim...@ce...> wrote: > Dear Roy, > > On Fri, 26 Sep 2008, Roy Stogner wrote: > >>> The only big catch that you need to worry about with that conversion >>> is vector resizing >> >> Whoops! There's actually one more catch, if you have an expansive >> definition of "C array". To save storage space, there's a trick in >> the standard: std::vector<bool> isn't really a std::vector, it's a >> data structure that encapsulates some bit twiddling to carry the >> requested information. > > Thank you very much for you reply. Where on the internet can I find > that document that says all there things? I recommend SGI's STL pages: http://www.sgi.com/tech/stl/table_of_contents.html and the comp.lang.c++.moderated newsgroup. cplusplus.com and the C++ FAQ Lite (http://www.parashift.com/c++-faq-lite/) are also very good. These sites are frequently easier to read than passages of the C++ standard, but if that's what you're after, you can always go there: http://www.open-std.org/jtc1/sc22/wg21/. -- John |
From: Roy S. <roy...@ic...> - 2008-09-26 13:51:59
|
On Fri, 26 Sep 2008, Tim Kroeger wrote: > Dear Roy, > > On Fri, 26 Sep 2008, Roy Stogner wrote: > >>> The only big catch that you need to worry about with that conversion >>> is vector resizing >> >> Whoops! There's actually one more catch, if you have an expansive >> definition of "C array". To save storage space, there's a trick in >> the standard: std::vector<bool> isn't really a std::vector, it's a >> data structure that encapsulates some bit twiddling to carry the >> requested information. > > Thank you very much for you reply. Where on the internet can I find > that document that says all there things? Unofficially, this is a good place to look for all things C++: http://www.parashift.com/c++-faq-lite/containers.html#faq-34.3 Officially, I can't find an online copy of the standard that doesn't require username/password, but here's Stroustrup (or a good impersonator) quoting it on comp.lang.c++: http://groups.google.com/group/comp.lang.c++/browse_thread/thread/8eadc19db7f52fd8/e856421fa563d42b?lnk=st&q=vector+storage+contiguous+stroustrup#e856421fa563d42b --- Roy |
From: Tim K. <tim...@ce...> - 2008-09-26 14:15:50
|
Dear Roy and John, thank you very much for your useful links. I am now totally satisfied. Best Regards, Tim -- Dr. Tim Kroeger Phone +49-421-218-7710 tim...@me..., tim...@ce... Fax +49-421-218-4236 MeVis Research GmbH, Universitaetsallee 29, 28359 Bremen, Germany Amtsgericht Bremen HRB 16222 Geschaeftsfuehrer: Prof. Dr. H.-O. Peitgen |