You might find some of the behavior of the DocData class generated by the ObjectARX Wizard puzzling:
- When you try to access one of your document specific data items, the CDocData constructor called many times
- The values that you initialized in my CDocData constructor seem to get lost, as if the initialization never happened.
The reason for this kind of behavior is that in the asdkDataManager template, we are using the Standard Template library (STL) "std::map" to hold all of your application’s Document specific data. This "map" is a what is known as a balanced binary tree and is created on the fly using the address of the AcApDocument (AcApDocument *) associated with the drawing as a key.
Because the tree is made on the fly, i.e. when you first try to access DocVars.docData() it will create new entries for you in the tree (as you would expect) but also, it will try and balance the tree so that access time is made extremely fast. It does this balancing by testing each key that it has to see if it’s lower or higher than the others it has already stored, it then makes the decision to sort the tree of not. The continual calling of your constructors is the std::map tree creating temporary objects so that it can copy them around and thus balance the tree. There is lots of information on STL on CodeGuru.com.
About the values being lost or appear uninitialized, this is likely because you have not implemented the same initialization in the CDocData::CDocData(CDocData &) copy constructor. This constructor is what STL mainly uses to create temporary objects for sorting purposes.

Leave a Reply