Avoid storage manipulation in open code

Probably the most error-prone thing you can do in C or C++ is raw storage manipulation. Any time you do pointer arithmetic, calculate lengths of storage blocks, or move them around, you risk an error that is extraordinarily difficult to track down and is among the worst kind of bug to find. Raw storage manipulation (such as storage copying and sizeof calculations) should never appear in open code; Taligent engineers must talk to an architect first. If you feel that you must do it, here are some guidelines to follow:

Don't do it! Don't try to save time by shortcutting the compiler because you know what it will do and you know a faster trick. When the compiler changes, the assumptions change, or if you get it wrong, you're going to be in hot water.

Use a collection class. The Taligent Collection classes already handle many kinds of storage manipulation including variable length arrays. The primitive forms of the Collection classes are extremely efficient. As an added bonus, the code is shared.

Wrap it in a class. Determine the basic abstraction that requires storage manipulation, and wrap it. That way, you only have to write the storage manipulation code once instead of spreading it throughout your code.

[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker