ENCYCLOPEDIA 4U .com



Encyclopedia Home Page

Google
  Web Encyclopedia4u.com

 

Reference (computer science)

In computer science, a reference is a small object containing information which refers to data instead of containing the data itself.

The basic idea of references is to store the whereabouts of data instead of data itself.

a := 2
b := a
a := 3
print a + b

In the above code, if a variable a contains a value rather than a reference, then the result is 2 + 3 = 5. On the contrary, if a is reference pointing to an integer 2, then the result would be 3 + 3 = 6.

The use of reference is motivated to create some flexibility in memory allocation and forming data structures and to improve runtime efficiency. References are primarily used to refer to objects or other data entities in memory, and construct data structures such as trees. In multi-element data structures, references can be used to form a link between nodes - for example, if you have one node, then you can access another node that the node refers to. Using references, objects can be stored at arbitrary locations in memory at runtime. Because typical data objects in computer programs reside in the memory, information of the location needs usually as small as 32 bits or 64 bits, which may allows to avoid costy duplication of memory blocks.

The mechanism of reference, if varying in implementation is one of foundmental programming language features and many modern programming languages support basic operations with references. Even some languages that support no direct way to locate an object arbitrary has some internal use of reference. For example, A calling convention, call by reference can be implemented with either explicit or implicit use of references.

Pointers are the most primitive type of reference, having mere memory address. Smart pointers are opaque data structures that requires to be accessed via particular functions or methods.

External and internal reference

Data structures containing data in some defined manner can store data either the "internal way" or the "external way". In the internal way, the structure copies actual data to its local data storage space, while in the external way, the structure only stores a reference to global data. The internal way is simple and safe but sometimes prohibitively inefficient in terms of memory usage and runtime performance. But, local data becomes out of date if an external process modifies the source of the data. Though more efficient than the internal way, the external way of using global references can mushroom into an unmanageable set of independent updates to the data.

External links

  • Pointer Fun With Binky Introduction to pointers in a 3 minute educational video - Stanford Computer Science Education Library




Content on this web site is provided for informational purposes only. We accept no responsibility for any loss, injury or inconvenience sustained by any person resulting from information published on this site. We encourage you to verify any critical information with the relevant authorities.



Copyright © 2005 Par Web Solutions All Rights reserved.
| Privacy

This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Reference (computer science)".