dcsimg
December 4, 2016
Hot Topics:

Inserting Registry Keys in a List Control

  • September 15, 2004
  • By Nancy Nicolaisen
  • Send Email »
  • More Articles »

Getting Ready to Walk The Registry Tree

To correctly initialize the tree view control, we have to walk all the way to the end of each of the branches of the Registry tree. Because we don't know the exact depth of the Registry hierarchy, and because it isn't likely to be symmetrical, we use recursion to find all the nodes in the tree. Recursion, in a nutshell, is when a function calls itself until some condition is met.

Recursion can be an indispensable tool for traversing hierarchical data, but it has risks. A runaway recursion will overflow the stack, and probably cause an unrecoverable failure (a.k.a. crash). Also, deep recursion is likely to cause the stack to be reallocated, which at least will slow your code down and at worst will expose other silent code defects. Use recursion if it makes sense, but don't overuse it. Here are a few tips on using recursion:

  • Try to minimize the size of parameter lists for recursive functions.
  • Try to minimize the size of local data in a recursive function.
  • Don't use recursion unless it is clearly required by the problem you are trying to solve.
  • Don't use recursion unless you can reasonably estimate the depth of the recursion.

Looking Ahead

In the next installment, we'll examine the code that recursively walks the Registry tree, finding and returning key values.

About the Author

Nancy Nicolaisen is a software engineer who has designed and implemented highly modular Windows CE products that include features such as full remote diagnostics, CE-side data compression, dynamically constructed user interface, automatic screen size detection, and entry time data validation.

In addition to writing for Developer.com, she has written several books, including Making Win 32 Applications Mobile.

# # #





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel