views:

40

answers:

2

I am trying to use C/C++ (Preferably C) to enumerate the entire Windows registry, I was using recursion to do this but I keep running into stack overflows, which i understand but im unable to think of anyway to do this without recusion. Advice on how to do this without recursion would be great, thx.

A: 

A bread-first search would be an obvious possibility. The basic idea is to use a queue of places to search. Start by putting the root into the queue, then repeat the following steps until the queue is empty:

  1. Get an item from the queue.
  2. Enumerate its contents.
  3. Add any links it contains to the queue.

...where "links" would be "subdirectories" for a file system, "subkeys" for the registry, etc.

Jerry Coffin
This sounds like it would work, do you have any links to tutorials or example code I could use? Cause I have no idea what your talking about :)
Tehyoda
I can't think of any right off anyway. Sorry.
Jerry Coffin
+2  A: 

As long as your recursion is just once per level of subkey, I don't see why this should overflow the stack. Sure the Windows registry is a nightmare, but I don't think its keys hierarchies are thousands of levels deep.

I suspect you're using some giant arrays on the stack, which is a bad idea in general but especially with recursion. Try allocating any large data you need with malloc instead.

R..
+1. I've done this with recursion myself and had no problems.
casablanca