"Phlip" <ph******@yahoo.comwrote in message
news:O6***************@newssvr25.news.prodigy.net. ..
Yes you can use it, but you need to follow STL rules as well as Win32 SDK
rules.
<snip>
Next...
>keyMap.insert(ValuePair("HKCR",HKEY_CLASSES_ROOT) );
One typically populates a map by assignment:
keyMap[L"HKCR"] = HKEY_CLASSES_ROOT.
The assignment method certainly looks nicer, but using insert seems to be
more efficient (if that matters in a given situation). Here's the code I
used to time it (unfortunately I had to use a non-Standard library to time
it in milliseconds, but it's fairly obvious what's going on):
#include <SDL.h>
#include <iostream>
#include <map>
#include <utility>
std::map<int,inttheMap;
unsigned int time_it(void (*f)())
{
unsigned int start = SDL_GetTicks();
f();
return SDL_GetTicks() - start;
}
void map_array()
{
for(int i=0; i<100000; ++i) theMap[i] = i;
}
void map_insert()
{
for(int i=0; i<100000; ++i) theMap.insert(std::make_pair(i,i));
}
int main(int argc, char *argv[])
{
SDL_Init(SDL_INIT_TIMER);
for(int i=1; i<=10; ++i)
{
std::cout << "TEST #" << i << '\n';
std::cout << "Associative array version: " << time_it(&map_array) <<
" milliseconds\n";
theMap.clear();
std::cout << "Insert version: " << time_it(&map_insert) << "
milliseconds\n\n";
theMap.clear();
}
SDL_Quit();
return 0;
}
The results I got were (condensed to save space):
TEST #1 Associative array version: 2549 milliseconds Insert version: 1977
milliseconds
TEST #2 Associative array version: 2434 milliseconds Insert version: 1959
milliseconds
TEST #3 Associative array version: 2429 milliseconds Insert version: 1959
milliseconds
TEST #4 Associative array version: 2424 milliseconds Insert version: 1953
milliseconds
TEST #5 Associative array version: 2481 milliseconds Insert version: 2070
milliseconds
TEST #6 Associative array version: 2502 milliseconds Insert version: 2039
milliseconds
TEST #7 Associative array version: 2496 milliseconds Insert version: 2137
milliseconds
TEST #8 Associative array version: 2569 milliseconds Insert version: 2083
milliseconds
TEST #9 Associative array version: 2585 milliseconds Insert version: 2013
milliseconds
TEST #10 Associative array version: 2545 milliseconds Insert version: 1994
milliseconds
This doesn't indicate that using insert is always the right way to go, but
it does seem to suggest that if you're adding a large number of key-value
pairs to a map, you might want to prefer insert. Assuming I haven't done
something stupid in my code, it would seem to be about 20% faster (the
associative array version takes roughly 2.5s each time, the insert version
takes about 2s, 2/2.5 roughly equals 0.8...). FWIW, I haven't tried it with
other data types, so for all I know this might just be the case when the key
type is int. YMMV :)
HTH,
Stu
Next, your computer already "knows" that HKCR is an alias for
HKEY_CLASSES_ROOT. Why are you telling it redundant information? (Answer
on an on-topic newsgroup! ;-)
>WalkRegistry("HKLM","Software\\ActiveState");
Have you softened this topic with a search on groups like codeproject.com?
There are lots of cute Registry wrappers out there...
--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!