 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
jordan@madsam.com Guest
|
Posted: Thu Dec 23, 2004 10:13 pm Post subject: Static instances of std::map allowed by C++ standard? |
|
|
I am curious if the C++ Standard (14882:1998(E) ) actually disallows
static instances of std::map as in:
#include <map>
std::map<int, int> foo;
int main() { return 0; }
When I use the Microsoft Visual Studio .NET 2003 compiler with some
code that uses static instances of maps, Rational Purify reports:
UMR: Uninitialized memory read in std::_Tree_nod
and tracing through the stack it seems associated with the allocator
initialization for std::map. Moreover when I replace the static map
instances with a Singleton pattern, Purify reports no errors.
The problem doesn't seem 100% consistent; for example, the 3-line
program above does _not_ seem to trigger the Rational Purify problem.
If static map instances are indeed forbidden, this would seem somewhat
invasive; for example, it would imply that CppUnit test fixture classes
can't contain any std::map data members (since static instances of
these classes are declared by the fixture registration macro).
Thanks in advance,
Jordan Samuels
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Maxim Yegorushkin Guest
|
Posted: Fri Dec 24, 2004 9:47 am Post subject: Re: Static instances of std::map allowed by C++ standard? |
|
|
On 23 Dec 2004 17:13:06 -0500, <jordan (AT) madsam (DOT) com> wrote:
| Quote: | I am curious if the C++ Standard (14882:1998(E) ) actually disallows
static instances of std::map as in:
#include <map
std::map
int main() { return 0; }
When I use the Microsoft Visual Studio .NET 2003 compiler with some
code that uses static instances of maps, Rational Purify reports:
|
[]
AFAIK, the standard does not disallow that.
<slightly offtopic>
There is a little problem with standard containers in a dll.
DllMain() docs for windoze clearly state that it is not safe to use
new/delete before and during DllMain(). The stadard allocator uses
::operator new/delete. So, to be on the safe side one might want to use
static instances of standard containers in a dll with a custom allocator,
that does not use ::operator new/delete, rather something like
HeapAlloc/HeapFree(GetProcessHeap(), ...).
--
Maxim Yegorushkin
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
P.J. Plauger Guest
|
Posted: Fri Dec 24, 2004 9:54 am Post subject: Re: Static instances of std::map allowed by C++ standard? |
|
|
<jordan (AT) madsam (DOT) com> wrote
| Quote: | I am curious if the C++ Standard (14882:1998(E) ) actually disallows
static instances of std::map as in:
#include <map
std::map
int main() { return 0; }
|
No, they're permitted.
| Quote: | When I use the Microsoft Visual Studio .NET 2003 compiler with some
code that uses static instances of maps, Rational Purify reports:
UMR: Uninitialized memory read in std::_Tree_nod
and tracing through the stack it seems associated with the allocator
initialization for std::map. Moreover when I replace the static map
instances with a Singleton pattern, Purify reports no errors.
|
It's probably a known bug in Purify. Default allocators are
zero-size objects which, under some circumstances, must be
made nonzero-size by adding one or more padding bytes.
Purify gets bent out of shape by attempts to copy the padding
bytes, at least under some circumstances.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
James Rafter Guest
|
Posted: Fri Dec 24, 2004 10:17 am Post subject: Re: Static instances of std::map allowed by C++ standard? |
|
|
| Quote: | I am curious if the C++ Standard (14882:1998(E) ) actually disallows
static instances of std::map as in:
|
There is no such prohibition. It's a bug in the implementation or
more than likely a false positive by purify.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Yechezkel Mett Guest
|
Posted: Wed Dec 29, 2004 9:08 pm Post subject: Re: Static instances of std::map allowed by C++ standard? |
|
|
"Maxim Yegorushkin" <e-maxim (AT) yandex (DOT) ru> wrote
| Quote: | On 23 Dec 2004 17:13:06 -0500, <jordan (AT) madsam (DOT) com> wrote:
DllMain() docs for windoze clearly state that it is not safe to
use
new/delete before and during DllMain().
|
Where does it say this?
Yechezkel Mett
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Maxim Yegorushkin Guest
|
Posted: Thu Dec 30, 2004 9:53 am Post subject: Re: Static instances of std::map allowed by C++ standard? |
|
|
{PLease take any further followups to private email as this is OT for
clc++m -mod}
On 29 Dec 2004 16:08:45 -0500, Yechezkel Mett <yechezkel (AT) emailaccount (DOT) com>
wrote:
| Quote: | DllMain() docs for windoze clearly state that it is not safe to
use
new/delete before and during DllMain().
Where does it say this?
|
Well, I could not find it in the current DllMain() docs, but I seem to
remember it was there, though I'm no longer sure.
--
Maxim Yegorushkin
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|