Smart Pointer Article Index for
Smart
Website Links For
Smart
 

Information About

Smart Pointer




Pointer usage is a major source of bugs: the constant allocation, deallocation and referencing that must be performed by a program written using pointers makes it very likely that some , the pointed object is destroyed too.

Several types of smart pointers exist. Some work with Reference Counting , others assigning ownership of the object to a single pointer. If the language supports automatic garbage collection, then this use of a smart pointer is unnecessary.


HANDLES

A ''handle'' is a particular kind of smart pointer. Handles are used when an application references blocks of memory or objects managed by another system, such as a Database or an Operating System . While a pointer literally contains the address of the item to which it refers, a handle is an Abstract reference controlled by a separate system; its opacity allows the referent to be relocated in memory by the system without invalidating the handle — impossible with pointers. The extra layer of Indirection also increases the control the managing system has over operations performed on the referent (see Information Hiding , Encapsulation ).

Handles were a popular solution to Memory Management in operating systems of the 1980s , such as Mac OS and Windows . Unix File Descriptor s are essentially handles. Like other desktop environments, the Windows API heavily uses handles to represent objects in the system and to provide a communication pathway between the operating system and User Space . For example, a window on the desktop is represented by a handle of type HWND.

Handles have fallen out of favour in recent times, as increases in available Memory and improved Virtual Memory algorithms have made the use of the simpler pointer more attractive.


SEE ALSO



EXTERNAL LINKS