Chapter 3 The Application Description Language

3.17 Dynamic Objects and Storage Management

You can create objects dynamically by using the new operator with the name of, or a handle to, a defined class. Such an object does not possess a name, and the user refers to it solely through the handle returned by the new operator. The object continues to exist even after exit from the enclosing scope, and if you are not careful, it is easy to destroy the handle accessing the object. Free the object using the delete operator before destroying its handle.

You can use the new operator with both special constructors and initializor blocks. The created object is initialized using the default Construct method unless a special constructor message intervenes between the new operator and the class name. The optional initializor block follows the class name.

You can also use the new operator to create new instances of base and compound types, including arrays. As with objects, the new operator returns a handle to the new instance and not the instance itself. Again, free the instance using the delete operator
Dynamic Instancing Example
class MyClass
{
string name;
upon Construct { ... }
upon CustomConstruct : list date { ... }
};

class Foo
{
on DoIt
{
handle aClassPtr, bClassPtr, aListPtr;

aClassPtr = new MyClass;
date = { 19, 'May, 1990 };
bClassPtr = new {'CustomConstruct, date}
=> MyClass { name = "M.I.T."; };
aListPtr = new list;
}
};

.

The clone operator (unimplemented) can be applied to an object or object handle to produce a copy of an object. The default method for doing this is to first simulate a use of the new operator on the object's class, and then do a recursive clone on member objects, a bitwise copy on members of base data types, and a deep copy on compound data members.

A non-default clone procedure is specified by defining a Clone method in the class to be cloned. This method is called with the handle of the cloned object as an argument. The method gets called after the simulated new, and substitutes for the remainder of the default clone procedure. Note that Clone is called as a method on the freshly cloned object, rather than on the object being cloned. Thus a Clone method should have no return value. Destroy cloned objects using the delete operator.


AM2 Documentation - 19 NOV 1996

Generated with Harlequin WebMaker