> hi,
> i've a requirement to scan the registry keys programatically in a console
[quoted text clipped - 5 lines]
> i've used a recursion to do so..but it's taking lot of time..
> is there any efficient way to acheive it.....
Well, I guess your other option is not to use recursion...
Any recursive algorithm can be written without recursion - just use large
enough stack for your local variables.
Instead of (pseudocode):
void ReadBranch( Branch b )
{
for each( Branch child in b.children )
ReadBranch( child )
}
you can write something like (very approximately):
Branch b;
push b;
while( stack not empty )
{
pop b;
for each( Branch child in b.children )
push child;
}
Günter Prossliner - 27 Sep 2007 10:53 GMT
Hello Ashot!
> Well, I guess your other option is not to use recursion...
>
> Any recursive algorithm can be written without recursion - just use
> large enough stack for your local variables.
Allthough this is right, the recrusion is not the problem in this case. The
cost of the function-calls are very small compared to the reading of the
Registry.
So an none-recrusive implementation will not run (noticable) faster in this
case.
@AVL: Scanning the whole registry takes time (just try to use the "Search"
Command of regedit.exe). All Nodes have to be loaded in this case. You may
need to adopt your algorithm (maybe you can skip some levels or cache parial
results in memory, ...) to get faster results.