Flylib.com

Books Software

 
 
 

5.5 Summary


5.5 Summary

In this chapter, we explore multithreaded and multiprocess designs. We introduced the concepts of locking objects and defined an object to manage the lock. We also contrast the UNIX and Win32 implementations of threads and process, and provide practical techniques for avoiding deadlocks.

We also discuss exception handling, and provide specific recommendations for top-level catch handlers, as well as detailed guidelines for creating your own exception handling framework. Smaller topics, such as catching specific types of exceptions like memory allocation errors, and exception specifications are also covered. See Figure 5.1 for a checklist of rules for handling exceptions. See Figure 5.2 for a checklist of guidelines for using assertions.

It is important to understand the effects of these constructs in both compile-time and run-time environments. The subsequent sections discuss a myriad of common compilers and their specific issues in handling constructs, such as dynamic casting, templates, and template specialization.

Finally, we provide a discussion of building an application such that it is ready for internationalization, should the business requirements require it. This section presents the high-level strategy and background to make the appropriate design decisions, while also providing a resource manager object for handling strings, and which uses XML to save and restore strings to files. We also present an alternative approach to managing strings using a gnu utility, gettext .

In Chapter 6, we use everything we have considered in the past chapters to finalize the design and implementation strategy for the image framework. In addition, we demonstrate how to integrate third-party libraries to further extend the framework's functionality and improve the performance of some image processing functions.


Chapter 6. Implementation Considerations

IN THIS CHAPTER

C++ Concepts

Memory Alignment

Handles and Rep objects

Iterators (pixel and STL)

Exception-Safe Locking

Image Framework Concepts

Image Datatypes

Image Coordinates

Image Storage

Image Object (Final Design)

Image Filtering Functions

Interfaces to Third-Party Software

In this chapter, we apply what we have learned through prototyping and examples to finalize the design for the image framework. The components of the framework are shown in Figure 6.1.

Figure 6.1. Image Framework Components

graphics/06fig01.gif

Our design has had many iterations, using a variety of C++ techniques. We started by using inheritance to create a framework that could handle numerous image types. It quickly became apparent in our subsequent prototype that templates both improved and simplified the design by eliminating most of the object hierarchy. However, we were still including image storage as a component of the image class, instead of separating it as an image component. We also explored using handles, but found they did nothing to improve the design. Once we prototyped a solution that separated storage from the image class, we knew that the final design was close at hand.

Each prototype was incomplete, but collectively they allowed us to test different design principles. We used a single, trivial, image processing function (computing thumbnail images) to observe the merits of each design. And, we wrote a unit test for each prototype to verify the correctness and the behavior of memory allocation, and to verify how pixels are accessed.

Often, the final design grows out of one or more prototypes. Sometimes it is obvious that you have hit on the right design, and other times it becomes an iterative process. From our prototypes , we applied the following ideas:

  • Image storage should be separate from the image processing functions. The image storage classes are independent of the image processing functions (but not vice versa).

  • Templates should be used for a more efficient design, allowing us to: produce a single version of code that works with any pixel type; optimize performance where needed by using specialization; and adapt our image storage component to use other memory allocators .