Instead of using simple pointers for working with objects, the ODA Platform implements the mechanism of smart pointers. A smart pointer is an abstract data type that simulates a pointer, providing additional features for accessing objects and managing memory at run-time, for example, automatic destroying of unused objects, throwing of exceptions, inspecting owners, or bounds checking. These additional features are intended to reduce issues caused by the misuse of pointers in the program while retaining efficiency. Smart pointers typically keep track of objects and they help with memory management at run-time.
Using smart pointers helps avoid issues typically caused by the misuse of raw pointers:
Smart pointer technology is used in application development. Every database object class is inherited from the OdRxClass, which implements the Runtime Type Identification mechanism that provides the ability to dynamically identify a class and get various information about it at run-time. Any database object can be created as an instance of OdRxObject by calling the static OdRxClass::createObject() function. This call creates the object and returns a smart pointer of specific type for the object.
For example, the following code fragment creates a circle object and acquires a smart pointer for it:
OdDbCirclePtr pCircle;
pCircle = OdDbCircle::createObject();
For more information about smart pointers, see the Smart Pointer topics in the ODA Kernel Developer Guide.
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.
|