Instantiation and Creation
 
 
 

The API separates the operations of instantiation and creation. Developers must initialize the universe before doing anything else. Since most objects are derived from the AlObject base class, safe type casting must be used to convert a base object to a derived object. Deleting objects and wrappers requires extra care.

The creation of an object often involves both instantiation and initialization. The initialization part, if it’s simple, can be put in the constructor of a class. However, if the initialization involves an operation that could fail (for example, memory allocation could fail), then the constructor is inadequate to convey failure. To address this, the API uses “create” methods to perform initialization because they return useful status codes. The following is an example of how an object should be created, and returns NULL if creation was unsuccessful.

// instantiation AlAmbientLight *ambientLight = new AlAmbientLight; if (ambientLight == NULL) {     return NULL; } // creation statusCode status = ambientLight->create(); switch(status) {     case sSuccess:
 break;     	case sInsufficientMemory:     	default: delete ambientLight; // Remember to free the memory      		return NULL; }