![]() |
![]() |
|
![]() |
![]() |
Encyclopedia :
R :
RE :
REF :
Reference (computer science) |
|
|
Reference (computer science)This article discusses a general notion of reference in computing. See also the more specific notion of reference used in C++.---- In computer science, a reference is a small object containing information which refers to data elsewhere, as opposed to containing the data itself. Accessing the value that a reference refers to is called dereferencing it. References are fundamental in constructing many data structures and in exchanging information between different parts of a program. References also increase flexibility in where objects can be stored, how they are allocated, and how they are passed between areas of code. As long as we can access a reference to the data, we can access the data through it, and the data itself need not be moved. They also make sharing of data between different code areas easier; each keeps a reference to it. The mechanism of references, if varying in implementation, is a fundamental programming language feature common to nearly all modern programming languages. Even some languages that support no direct use of references have some internal or implicit use. For example, the call by reference calling convention can be implemented with either explicit or implicit use of references. Pointers are the most primitive and error-prone but also one of the most powerful and efficient types of references, storing only the address of an object in memory. Smart pointers are opaque data structures that act like pointers but can only be accessed through particular methods. Formal definitionWhen we need to be precise, we define references in terms of a dereferencing function d, where d is a partial function from an uninterpreted set L of locations to a set of values. The set of values includes all possible values of all datatypes. Then, a reference is simply an element of L, and it is dereferenced by applying d to it. The definition of d varies as new data is allocated and old data deallocated. In other models, such as the reachability graphs used by garbage collection, a reference is represented as an edge in a directed graph. It connects two vertices representing objects, pointing from the one containing the reference to the object being referenced. External and internal storageIn many data structures, large, complex objects are composed of smaller objects. These objects are typically stored in one of two ways:
|
|
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License. |
|
| © 2008 Chamas Enterprises Inc. |