Drawings SDK Developer Guide > Working with .dwg Files > Introduction > Basics of Database Operations and Database Objects > Using Smart Pointer Technology
Using Smart Pointer Technology

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:

  • Memory leaks — The program stores an object in its own dynamic memory, but does not have a pointer that stores the address of this object — the object exists, but nothing uses it.
  • Dangling of pointers — A pointer stores the address of an object that is destroyed in the program — the pointer refers to an object that does not exist.
  • Incorrect exception throwing — The pointer is NULL or refers to an object of another type while the program throws an exception and someone tries to de-reference it — the exception operates on an incorrect pointer.
  • Out of scope — The pointer gets out of the scope of available memory.

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.