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:
- Get an item from the queue.
- Enumerate its contents.
- Add any links it contains to the queue.
...where "links" would be "subdirectories" for a file system, "subkeys" for the registry, etc.
Jerry Coffin
2010-10-06 15:29:47
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
2010-10-06 16:06:40
I can't think of any right off anyway. Sorry.
Jerry Coffin
2010-10-06 16:51:08
+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..
2010-10-06 15:37:10