valgrind fixes, vector pre-allocation

Benjamin Kosnik
Thu Apr 11 19:50:00 GMT 2002

I'm in the process of running the libstdc++-v3 testsuite, collecting
all the shared executables, and running them under valgrind, which is
an uber-leak-finder. I would like to have a valgrind-clean-libstdc++
as soon as possible.

So far, I've changed the way locales are initialized, in particular
most of the lossage from the "C" locale being leaked. From 52
allocations, I'm now down to 19.....

However, getting rid of the rest means either

1) special-casing std::locale("C")'s _Impl data structure....

2) or finding a way to pre-allocate the _M_facets member for std::locale("C").

Perhaps there are other ways, but these two seem the most likely
chances for success.

I'm looking for help and ideas for the second option. Although a
vector of facet*'s is cool, it's a bit of overkill for a locale that
isn't going to grow or change. Especially when std::vector(28, 0) ends
up allocating 4400 bytes.

Here's a simple C++ example that explains what I'd like to
do. Suggestions and help will be mightily appreciated.....

#include <vector>

typedef std::vector<void*> vector_type;

struct impl
  vector_type	_M_facets;

  impl(bool = false) : _M_facets(28) { }

int main()
  impl test; // so that no allocations take place......
  return 0;

More information about the Libstdc++ mailing list