This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

(C++) High memory usage with templates


Hi,

In addition to my previous message, here is a short program that
demonstrates this behaviour.

== start memory-test.cc ==
//
// Demonstrate the high memory usage when compiling with templates
//
// With -O2 turned on, cc1plus uses about 10megs compiling
// this. Without optimisation, it uses about 6megs.

#include <vector>
#include <map>
#include <string>

int main()
{
	typedef map<string, unsigned short> myMap;
	typedef vector<myMap> someMaps;

	myMap fred, barney;
	someMaps wilma;

	fred.insert(pair<string, unsigned short>("foo", 1));
	fred.insert(pair<string, unsigned short>("bar", 2));

	barney.insert(pair<string, unsigned short>("foo", 2));
	barney.insert(pair<string, unsigned short>("bar", 1));

	wilma.push_back(fred);
	wilma.push_back(barney);
}
== end memory-test.cc ==

--
Chris Butler
<chrisb@sandy.force9.co.uk>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]