There are three ways to refer to an element of a database:
There are multiple methods because of the various mechanisms of storing elements in a database and using them at run-time. Each mechanism has its own advantages and area for application.
When a database is stored in a file, its elements must have unique identifiers within the scope of the database. Such identification allows distinguishing one element stored in the database from another. This identification is useful when a program works with a single database.
When a database is loaded in memory, its database element becomes accessible to other elements of a program, including other databases loaded through other database elements. As a result, any unique identifiers within a single database may not be unique across multiple databases, but the program must have a unique element identifier throughout its run-time session that identifies the element 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 database at run-time, meaning that an element can be used with various procedures at the same time. When several programs simultaneously use a database or several procedures simultaneously use the same element at run-time, it must persist the element and point to it throughout the current session until the element has been edited or used. Therefore, the program must have a specific pointing mechanism that can take an element 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.
A handle uniquely identifies an element within the scope of a particular database. When an element is added to a database, the database automatically creates a unique identifier for it (handle) and associates it with the element. The associated identifier becomes fixed for the element within the scope of the database. When a database is saved in a file, the handle is saved together with the element it identifies. When a database is loaded from a file, the handle is loaded together with the element and has the same value that it had before being saved. For more details, see Identifying an element using a Handle.
An identifier (ID) uniquely identifies an element within the scope of all databases loaded at run-time. When an element is added into a database, the database automatically creates a unique ID for it and associates it with the element and its handle. An ID exists only during the current run-time session until a database is loaded in memory. When a database is saved in a file, its IDs are not saved. When a database is closed, its elements lose the IDs assigned to them. When a database is loaded from a file, the database creates new IDs for elements.
When an element refers to another element allocated in another database during run-time, its ID has been redirected from one database to another database. For more details, see Identifying an element using an ID.
A pointer addresses and manipulates an element at run-time. A pointer directly refers to an element in memory, allows access to its properties, and controls it during the current scope of a program. To use a pointer, the element 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 becomes out of scope, and it will be destroyed. As a result, the pointer loses its element and the element is released. When a database is saved in a file, the pointer is not saved.
Smart pointer technology is used for pointing to elements in a database at run-time. Smart pointers automatically control the referencing of elements using the reference counter embedded in each element of a database. When a smart pointer gets an address of an element, it increases the element's reference counter. When a smart pointer is assigned to another element, it increases its reference counter and decreases the reference counter of the element to which it pointed at. When a smart pointer gets a NULL value or is destroyed, it decreases the element's reference counter. When the reference counter becomes zero, the element is released. A program obtains a pointer to an element using the element ID. For more details, see Using Smart Pointer Technology.
When a database is placed in a file, it stores its own elements together with handles. Each element of a file is identified by its own handle. When a database is opened, the program loads it in memory and the database exists in run-time. This operation creates the database element that represents an interface for assessing the elements stored in the database.
During the loading, the database generates IDs for each element and associates them with elements and handles. An ID is kept by the database throughout the current run-time session until the database is closed. An ID identifies an element in run-time, has access to the element, and can manipulate the element. When a program or its procedure needs to work with an element, it creates a smart pointer to an element and uses the associated ID to obtain the address and access to the element. The ID instance has a specific method for opening an element that accommodates the element ability to be shared between other procedures and could already be in use. Using the element ID, the program obtains the smart pointer to the associated element of a database. Using the obtained smart pointer, the program can manipulate the element and modify its properties. The smart pointer refers to the element in a current computational process.
When a computational process is finished and an element is no longer needed, the program must release the element. To release an element, the program or its procedure must assign a NULL value to the smart pointer that references the element or it must delete the pointer. After release, the element continues to exist in the database and can again be obtained using its element ID through other smart pointers. When work is finished and the database 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 elements. After closing, elements of a database are not accessible to the program.
Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.
|