Handle (computing)
From Wikipedia, the free encyclopedia
This article does not cite any references or sources. (May 2007) Please help improve this article by adding citations to reliable sources. Unverifiable material may be challenged and removed. |
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 descriptors 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
.
Traditional, doubly-indirect 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. However, many operating systems still apply the term to pointers to opaque, "private" data structures, or indexes into internal arrays passed from one process to its clients.