public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Large map<srting,string> Initialization
@ 2005-05-22 12:39 Tom Browder
  2005-05-22 13:17 ` Stefan Strasser
  2005-05-22 16:20 ` Florian Weimer
  0 siblings, 2 replies; 4+ messages in thread
From: Tom Browder @ 2005-05-22 12:39 UTC (permalink / raw)
  To: gcc-help

I need a map with many string pairs and I instantiate it like this:

  map<const string,const string> mymap;
  mymap.insert(make_pair("long_string1", "long_string_val1"));
  ...
  mymap.insert(make_pair("long_string10000", "long_string_val10000"));

The strings generally are about 30-40 characters in length.

The source file is very long and g++ (4.0) takes a very long time (and a
large amount of memory) to compile it.

I have broken the file into smaller pieces (which helps with memory usage)
but the total compile time is about the same.

Note that the map is never modified after the initial load, it is merely
used for looking up the values.

Several questions:

1.  Is there a better way to initialize such a map?

2.  Are there g++ options that would help?

3.  Are there linker/loader tricks that would help?

Thanks.

Tom Browder

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Large map<srting,string> Initialization
  2005-05-22 12:39 Large map<srting,string> Initialization Tom Browder
@ 2005-05-22 13:17 ` Stefan Strasser
  2005-05-22 15:32   ` Tom Browder
  2005-05-22 16:20 ` Florian Weimer
  1 sibling, 1 reply; 4+ messages in thread
From: Stefan Strasser @ 2005-05-22 13:17 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help

Tom Browder schrieb:
> I need a map with many string pairs and I instantiate it like this:
> 
>   map<const string,const string> mymap;

first const is not required, key type of a map is always const.

>   mymap.insert(make_pair("long_string1", "long_string_val1"));
>   ...
>   mymap.insert(make_pair("long_string10000", "long_string_val10000"));
> 
> The strings generally are about 30-40 characters in length.
> 
> The source file is very long and g++ (4.0) takes a very long time (and a
> large amount of memory) to compile it.

GCC does not have a very good algorithm complexity in this case it seems.
(I tried, doubling the "insert" statements quintupled compilation time).

this is compiled much faster(and will run faster):

std::pair<std::string,std::string> a[]={
	std::make_pair("asdklfj","kljsfd"),
	// ...
};

std::map<std::string,std::string> b(a,a + (sizeof(a) / sizeof(*a)));

> 
> I have broken the file into smaller pieces (which helps with memory usage)
> but the total compile time is about the same.
> 
> Note that the map is never modified after the initial load, it is merely
> used for looking up the values.
> 
> Several questions:
> 
> 1.  Is there a better way to initialize such a map?
> 
> 2.  Are there g++ options that would help?
> 
> 3.  Are there linker/loader tricks that would help?
> 
> Thanks.
> 
> Tom Browder
> 
> 
> 



-- 
Stefan Strasser

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: Large map<srting,string> Initialization
  2005-05-22 13:17 ` Stefan Strasser
@ 2005-05-22 15:32   ` Tom Browder
  0 siblings, 0 replies; 4+ messages in thread
From: Tom Browder @ 2005-05-22 15:32 UTC (permalink / raw)
  To: 'Stefan Strasser'; +Cc: gcc-help

Thanks, Stefan, I'll try your suggestions.  They should help immensely.

-Tom

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Large map<srting,string> Initialization
  2005-05-22 12:39 Large map<srting,string> Initialization Tom Browder
  2005-05-22 13:17 ` Stefan Strasser
@ 2005-05-22 16:20 ` Florian Weimer
  1 sibling, 0 replies; 4+ messages in thread
From: Florian Weimer @ 2005-05-22 16:20 UTC (permalink / raw)
  To: Tom Browder; +Cc: gcc-help

* Tom Browder:

> 1.  Is there a better way to initialize such a map?

You could use a (preferably sorted) array of {"long_string1",
"long_string_val1"} structure values to initialize the map.  Depending
on your needs, you might be able to skip the map altogether and just
use a binary search to locate the correct strings.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-22 16:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-22 12:39 Large map<srting,string> Initialization Tom Browder
2005-05-22 13:17 ` Stefan Strasser
2005-05-22 15:32   ` Tom Browder
2005-05-22 16:20 ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).