Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Identifying the Objects of Databases > Concept of Identification
Concept of Identification

There are three mechanisms for referring to an object of a database, by:

  • handle
  • pointer
  • ID

The various mechanisms are due to the various mechanisms of storing objects in a drawing and using them at run-time. Each mechanism has its own advantages and area for application.

When a drawing is stored in a file, its database can identify its own objects. As a result, each object must have a unique identifier within the scope of a drawing among the other objects stored in the drawing. This identification is useful when a program works with a single drawing.

When a drawing is loaded in memory, its database object becomes accessible to other objects of a program, including other drawings loaded through other database objects. As a result, any unique identifiers within a single database may not be unique across multiple databases, but the program must have a unique object identifier throughout its run-time session that identifies the object across all loaded databases. This type of identification requirement is useful when a program cross-references between databases. Additionally, some program procedures can share a drawing at run-time, meaning that an object can be used with various procedures at the same time. When several programs simultaneously use a drawing or several procedures simultaneously use the same object at run-time, it must persist the object and point to it throughout the current session until the object has been edited or used. Therefore, the program must have a specific pointing mechanism that can take an object at run-time, mark it as in-use, address it in memory, control it throughout a session, count the number of references to it, and release it when it is no longer used.

Handles

A handle uniquely identifies an object within the scope of a particular database. When an object is added to a database, the database automatically creates it a unique identifier (handle) and associates it with the object. The associated identifier becomes fixed for the object within the scope of the database. When a drawing is saved in a file, the handle is saved together with the object it identifies. When a drawing is loaded from a file, the handle is loaded together with the object and has the same value that it had before being saved. For more details, see Identification using a Handle.

IDs

An ID uniquely identifies an object within the scope of all databases loaded at run-time. When an object is added into a database, the database automatically creates it a unique ID and associates it with the object and its handle. An ID exists only during the current run-time session until a drawing is loaded in memory. When a drawing is saved in a file, its IDs are not saved. When a drawing is closed, its objects lose the IDs assigned to them. When a drawing is loaded from a file, the database creates new IDs for objects. When an object of a database refers to another object of another database during run-time, its ID has been redirected from one database to another database. For more details, see Identification using an ID.

Pointers

A pointer addresses and manipulates an object at run-time. A pointer directly refers to an object in memory, allows access to its properties, and controls it during the current scope of a program. To use a pointer, the object must exist and the database must be loaded in memory. A pointer exists only in the scope of the program or procedure that uses it. When a program or procedure finishes, the pointer is out of scope, and it is destroyed. As a result, the pointer loses its object and the object is released. When a drawing is saved in a file, the pointer is not saved.

Smart pointer technology is used for pointing to objects in a database at run-time. Smart pointers automatically control the referencing of objects using the reference counter embedded in each object of a database. When a smart pointer gets an address of an object, it increases the object's reference counter. When a smart pointer is assigned to another object, it increases its reference counter and decreases the reference counter of the object to which it pointed. When a smart pointer gets a NULL value or is destroyed, it decreases the object's reference counter. When the reference counter becomes zero, the object is released. A program obtains a pointer to an object using the object ID. For more details, see Identification using a Pointer.

Accessing an object

When a drawing is placed in a file, it stores its own objects together with handles. Each object of a file is identified by its own handle. When a drawing is opened, the program loads it in memory and the drawing exists in run-time. This operation creates the database object that represents an interface for assessing the objects stored in the drawing.

During loading, the database generates IDs for each object and associates them with objects and handles. An ID is kept by the database throughout the current run-time session until the database is closed. An ID identifies an object in run-time, has access to the object, and can manipulate the object. When a program or its procedure needs to work with an object, it creates a smart pointer to an object and uses the associated ID to obtain the address and access to the object. The ID instance has a specific method for opening an object that accommodates the object ability to be shared between other procedures and could already be in use. Using the object ID, the program obtains the smart pointer to the associated object of a database. Using the obtained smart pointer, the program can manipulate the object and modify its properties. The smart pointer refers to the object in a current computational process.

When a computational process is finished and an object is no longer needed, the program must release the object. To release an object, the program or its procedure must assign a NULL value to the smart pointer that references the object or it must delete the pointer. After release, the object continues to exist in the database and can again be obtained using its object ID through other smart pointers. When work is finished and the drawing is no longer needed, the program must close the database and free the memory. The close operation deletes all IDs that existed in the current run-time session, but it does not change the handles associated with objects. After closing, objects of a drawing are not accessible to the program.

See Also

Identifying the Objects of Databases

Object Reference Types

Copyright © 2002 – 2021. Open Design Alliance. All rights reserved.