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 := 2b := aa := 3print a + b
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.
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 and internal reference
External links