48岁属什么生肖| 睡美人最怕什么脑筋急转弯| 子宫内膜9mm意味着什么| 什么是自由度| 残疾证有什么补贴| 格物穷理是什么意思| 唾液臭是什么原因| 后背长痘是什么原因| 挂面是什么面| 淋巴癌有什么症状| 片状低回声区什么意思| 尿酸偏低是什么原因| 什么是酸性食物| 甲鱼吃什么东西| 心什么神往| 复方是什么意思| 谩骂是什么意思| 脑袋进水什么意思| 银杏是什么| 分率是什么意思| 犯月是什么意思| 手指甲有黑色条纹是什么原因| 美味佳肴是什么意思| oce是什么牌子| 醋泡洋葱有什么功效| 饱经风霜是什么生肖| 4月20日什么星座| 喝酒之前吃什么保护胃| 尿频尿黄是什么原因| 喉咙痛吃什么水果好| 胆囊壁稍毛糙是什么意思| 生物医学工程专业学什么| 梦见捉黄鳝是什么意思| 天河水命是什么意思| 吃什么补气养血最快| 陆代表什么数字| 长痘痘用什么药| 脐血流检查是什么| 洗面奶和洁面乳有什么区别| 什么牛排最好吃| 梅毒是什么| 岳字五行属什么| 晚上吃什么容易入睡| 上学是为了什么| 粘胶纤维是什么| 翎字五行属什么| 吃什么东西| 丙子日是什么意思| ghost是什么意思| 老是胃疼是什么原因| 肚子一直响是什么原因| 大天真香是什么意思| 黛是什么颜色| 四级什么时候报名| 什么饭不能吃| 无异于是什么意思| 龟头炎什么症状| hf医学上是什么意思| 氮肥是什么肥| 喉咙发炎不能吃什么食物| 经常头疼是什么原因| 耳垂长痘痘是什么原因| 什么是牙齿根管治疗| 香薰是什么| 大卡是什么意思| 三伏是什么时候| alds是什么病| 面包是什么意思| 胃炎是什么原因引起的| 足勺念什么| 眼睛疼吃什么药效果最好| 亚型是什么意思| 世界上最大的岛是什么岛| 男人到了什么年龄就性功能下降| 坚持是什么意思| 11月16日是什么星座| 脾大是怎么回事有什么危害| 外痔疮有什么症状| 青瓜炒什么好吃| 腹泻吃什么食物好| 梦见很多坟墓是什么意思| 小孩长白头发是什么原因| 8月11是什么星座| 脱肛是什么意思| 剖腹产坐月子吃什么| 什么样的智齿不需要拔| 口吐白沫是什么原因| 陈皮的功效与作用主要治什么病| 白浆是什么| 三点水加个真念什么| 熬夜为什么会胖| 荷尔蒙是什么| 甲功不正常有什么表现| rhino是什么意思| 体雕是什么| 6542是什么药| 牙套脸是什么样| 横纹肌溶解什么意思| 苏麻为什么不嫁给康熙| 头晕是什么感觉| 感染幽门螺旋杆菌会出现什么症状| 乳腺术后吃什么最好| onlycook是什么牌子| 什么的脚| 77年的蛇是什么命| 阳历一月份是什么星座| 什么应外合| 为什么有眼袋是什么原因引起的| 失眠用什么药好| 吃什么大便能特别通畅| 閪什么意思| 桑树枝煮水有什么功效| 甲状腺桥本是什么意思| 印度人为什么不吃猪肉| 红绿色盲是什么遗传病| 做梦梦见狼是什么意思| 十指不沾阳春水是什么意思| 蝗虫的呼吸器官是什么| 梦见金蛇有什么预兆| 抽动症是什么引起的| 尿道炎吃什么药好得快| 30岁属什么| 男生适合养什么小型犬| 日本全称是什么| 情窦初开什么意思| 春秋大梦是什么意思| 腋下淋巴结肿大挂什么科| 哺乳期什么时候来月经正常| 富豪是什么意思| 针对是什么意思| 心动过缓吃什么药最好| 百年好合什么意思| 心脏无力吃什么药最好| 什么人容易得肾结石| 什么一现| 614是什么星座| 小意思是什么意思| dhc是什么| 毛主席的女儿为什么姓李| 肾彩超能查出什么| 泰迪吃什么| 泡芙是什么意思| 黑马是什么意思| 丙火是什么意思| 美白吃什么| 胆囊炎属于什么科| 嘴唇肿起来一般是什么原因引起的| 线性是什么意思| 喝黄芪水有什么副作用| 什么是签注| 白癜风是什么引起的| 肝郁气滞是什么意思| 侍寝是什么意思| 农历11月11日是什么星座| 下寒上热体质吃什么中成药| 痛风能吃什么| 什么情况下需要做造影| 氧化亚铜什么颜色| 外公的哥哥叫什么| 鱼肝油是什么| 夏季喝什么汤好| 四月二十一是什么星座| 滑膜疝是一种什么病| 染发膏用什么能洗掉| pi是什么| 东北易帜是什么意思| bk病毒是什么| 包皮炎挂什么科| 小暑是什么时候| 上海最高楼叫什么大厦有多少米高| 20分贝相当于什么声音| 浮粉是什么原因引起的| 尿液弱阳性什么意思| 大象吃什么食物| 男女双修是什么意思| 太阳星座是什么意思| 鼻子干痒是什么原因| 十面埋伏是什么生肖| 狗狗胰腺炎吃什么药| 伦字五行属什么| 为什么女娲是一条蛇| 骨折什么感觉| 尿隐血是什么问题| 漫反射是什么意思| 神甫是什么意思| 出岫是什么意思| 吃桃子有什么好处| 恶寒什么意思| 大男子主义的男人喜欢什么样的女人| 八岁属什么生肖| 人贫血吃什么补得快| 什么是间质性肺炎| 生姜红糖水有什么作用| 煜怎么读音是什么意思| 云的五行属性是什么| 海鲜都有什么| 夜尿频多是什么原因| 属猴的守护神是什么菩萨| 手掌心痒是什么原因| 牛叉是什么意思| 机车是什么意思| 丑人多作怪什么意思| 辟加木念什么| fl什么意思| 女人什么时候最想男人| 纳氏囊肿是什么意思| 231是什么意思| 甲状腺结节吃什么食物好| 大连靠近什么海| 手不自主颤抖是什么病| 什么可以祛斑| 阴虚火旺吃什么好| 肝不好吃什么中成药| 卵泡长得慢是什么原因造成的| 淋巴肿了吃什么消炎药| c反应蛋白是什么| 撇嘴表情什么意思| 变白吃什么| 针眼用什么药| 芙蓉什么意思| 冬虫夏草有什么作用| 弱水是什么意思| 准备要孩子需要注意什么| 胃在什么地方| 什么是钙化| 中药学是干什么的| 绍兴有什么大学| 什么呀什么| 水分是什么意思| 小米叫什么| 突然头晕是什么情况| 青柠檬和黄柠檬有什么区别| 什么米好吃又香又软| 坐月子吃什么水果| 夏天是什么样的| 用什么可以美白| 心肌标志物是查什么的| 为什么白带是绿色| 文化是指什么| 睡觉趴着睡是什么原因| 两面三刀是什么生肖| 仰天长叹的意思是什么| 口腔扁平苔藓吃什么药好得快| 白色的玉是什么玉| 优质是什么意思| 杏子不能和什么一起吃| 灰枣和红枣有什么区别| 吗丁啉有什么功效| 胸片是什么| 太抽象了是什么意思| 省政协常委是什么级别| 查甲状腺挂什么科| 范思哲手表什么档次| 睡几个小时就醒了是什么原因| 颠勺是什么意思| 52年属什么生肖| 政协主席是什么级别| 脖子为什么有颈纹| 16588a是什么尺码女装| 陈晓和赵丽颖为什么分手| 发配是什么意思| 夹生饭是什么意思| 难于上青天是什么意思| 鞑靼是什么意思| 百度Jump to content

P2P消费贷变形“首付贷” 一次性交手续费3%-4%

From Wikipedia, the free encyclopedia
百度 做中国人民和中华民族的主心骨,就要始终自身过硬、勇于自我革命。

In computer programming, a reference is a value that enables a program to indirectly access a particular datum, such as a variable's value or a record, in the computer's memory or in some other storage device. The reference is said to refer to the datum, and accessing the datum is called dereferencing the reference. A reference is distinct from the datum itself.

A reference is an abstract data type and may be implemented in many ways. Typically, a reference refers to data stored in memory on a given system, and its internal value is the memory address of the data, i.e. a reference is implemented as a pointer. For this reason a reference is often said to "point to" the data. Other implementations include an offset (difference) between the datum's address and some fixed "base" address, an index, or identifier used in a lookup operation into an array or table, an operating system handle, a physical address on a storage device, or a network address such as a URL.

Formal representation

[edit]

A reference R is a value that admits one operation, dereference(R), which yields a value. Usually the reference is typed so that it returns values of a specific type, e.g.:[1][2]

interface Reference<T> {
    T value();
}

Often the reference also admits an assignment operation store(R, x), meaning it is an abstract variable.[1]

Use

[edit]

References are widely used in programming, especially to efficiently pass large or mutable data as arguments to procedures, or to share such data among various uses. In particular, a reference may point to a variable or record that contains references to other data. This idea is the basis of indirect addressing and of many linked data structures, such as linked lists. References increase flexibility in where objects can be stored, how they are allocated, and how they are passed between areas of code. As long as one can access a reference to the data, one 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.

References can cause significant complexity in a program, partially due to the possibility of dangling and wild references and partially because the topology of data with references is a directed graph, whose analysis can be quite complicated. Nonetheless, references are still simpler to analyze than pointers due to the absence of pointer arithmetic.

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.

Examples

[edit]

Pointers are the most primitive type of reference. Due to their intimate relationship with the underlying hardware, they are one of the most powerful and efficient types of references. However, also due to this relationship, pointers require a strong understanding by the programmer of the details of memory architecture. Because pointers store a memory location's address, instead of a value directly, inappropriate use of pointers can lead to undefined behavior in a program, particularly due to dangling pointers or wild pointers. Smart pointers are opaque data structures that act like pointers but can only be accessed through particular methods.

A handle is an abstract reference, and may be represented in various ways. A common example are file handles (the FILE data structure in the C standard I/O library), used to abstract file content. It usually represents both the file itself, as when requesting a lock on the file, and a specific position within the file's content, as when reading a file.

In distributed computing, the reference may contain more than an address or identifier; it may also include an embedded specification of the network protocols used to locate and access the referenced object, the way information is encoded or serialized. Thus, for example, a WSDL description of a remote web service can be viewed as a form of reference; it includes a complete specification of how to locate and bind to a particular web service. A reference to a live distributed object is another example: it is a complete specification for how to construct a small software component called a proxy that will subsequently engage in a peer-to-peer interaction, and through which the local machine may gain access to data that is replicated or exists only as a weakly consistent message stream. In all these cases, the reference includes the full set of instructions, or a recipe, for how to access the data; in this sense, it serves the same purpose as an identifier or address in memory.

If we have a set of keys K and a set of data objects D, any well-defined (single-valued) function from K to D ∪ {null} defines a type of reference, where null is the image of a key not referring to anything meaningful.

An alternative representation of such a function is a directed graph called a reachability graph. Here, each datum is represented by a vertex and there is an edge from u to v if the datum in u refers to the datum in v. The maximum out-degree is one. These graphs are valuable in garbage collection, where they can be used to separate accessible from inaccessible objects.

External and internal storage

[edit]

In many data structures, large, complex objects are composed of smaller objects. These objects are typically stored in one of two ways:

  1. With internal storage, the contents of the smaller object are stored inside the larger object.
  2. With external storage, the smaller objects are allocated in their own location, and the larger object only stores references to them.

Internal storage is usually more efficient, because there is a space cost for the references and dynamic allocation metadata, and a time cost associated with dereferencing a reference and with allocating the memory for the smaller objects. Internal storage also enhances locality of reference by keeping different parts of the same large object close together in memory. However, there are a variety of situations in which external storage is preferred:

  • If the data structure is recursive, meaning it may contain itself. This cannot be represented in the internal way.
  • If the larger object is being stored in an area with limited space, such as the stack, then we can prevent running out of storage by storing large component objects in another memory region and referring to them using references.
  • If the smaller objects may vary in size, it is often inconvenient or expensive to resize the larger object so that it can still contain them.
  • References are often easier to work with and adapt better to new requirements.

Some languages, such as Java, Smalltalk, Python, and Scheme, do not support internal storage. In these languages, all objects are uniformly accessed through references.

Language support

[edit]

Assembly

[edit]

In assembly language, it is typical to express references using either raw memory addresses or indexes into tables. These work, but are somewhat tricky to use, because an address tells you nothing about the value it points to, not even how large it is or how to interpret it; such information is encoded in the program logic. The result is that misinterpretations can occur in incorrect programs, causing bewildering errors.

Lisp

[edit]

One of the earliest opaque references was that of the Lisp language cons cell, which is simply a record containing two references to other Lisp objects, including possibly other cons cells. This simple structure is most commonly used to build singly linked lists, but can also be used to build simple binary trees and so-called "dotted lists", which terminate not with a null reference but a value.

C/C++

[edit]

The pointer is still one of the most popular types of references today. It is similar to the assembly representation of a raw address, except that it carries a static datatype which can be used at compile-time to ensure that the data it refers to is not misinterpreted. However, because C has a weak type system which can be violated using casts (explicit conversions between various pointer types and between pointer types and integers), misinterpretation is still possible, if more difficult. Its successor C++ tried to increase type safety of pointers with new cast operators, a reference type &, and smart pointers in its standard library, but still retained the ability to circumvent these safety mechanisms for compatibility.

Fortran

[edit]

Fortran does not have an explicit representation of references, but does use them implicitly in its call-by-reference calling semantics. A Fortran reference is best thought of as an alias of another object, such as a scalar variable or a row or column of an array. There is no syntax to dereference the reference or manipulate the contents of the referent directly. Fortran references can be null. As in other languages, these references facilitate the processing of dynamic structures, such as linked lists, queues, and trees.

Object-oriented languages

[edit]

A number of object-oriented languages such as Eiffel, Java, C#, and Visual Basic have adopted a much more opaque type of reference, usually referred to as simply a reference. These references have types like C pointers indicating how to interpret the data they reference, but they are typesafe in that they cannot be interpreted as a raw address and unsafe conversions are not permitted. References are extensively used to access and assign objects. References are also used in function/method calls or message passing, and reference counts are frequently used to perform garbage collection of unused objects.

Functional languages

[edit]

In Standard ML, OCaml, and many other functional languages, most values are persistent: they cannot be modified by assignment. Assignable "reference cells" provide mutable variables, data that can be modified. Such reference cells can hold any value, and so are given the polymorphic type α ref, where α is to be replaced with the type of value pointed to. These mutable references can be pointed to different objects over their lifetime. For example, this permits building of circular data structures. The reference cell is functionally equivalent to a mutable array of length 1.

To preserve safety and efficient implementations, references cannot be type-cast in ML, nor can pointer arithmetic be performed. In the functional paradigm, many structures that would be represented using pointers in a language like C are represented using other facilities, such as the powerful algebraic datatype mechanism. The programmer is then able to enjoy certain properties (such as the guarantee of immutability) while programming, even though the compiler often uses machine pointers "under the hood".

Perl/PHP

[edit]

Perl supports hard references, which function similarly to those in other languages, and symbolic references, which are just string values that contain the names of variables. When a value that is not a hard reference is dereferenced, Perl considers it to be a symbolic reference and gives the variable with the name given by the value.[3] PHP has a similar feature in the form of its $$var syntax.[4]

See also

[edit]

References

[edit]
  1. ^ a b Sherman, Mark S. (April 1985). Paragon: A Language Using Type Hierarchies for the Specification, Implementation, and Selection of Abstract Data Types. Springer Science & Business Media. p. 175. ISBN 978-3-540-15212-5.
  2. ^ "Reference (Java Platform SE 7)". docs.oracle.com. Retrieved 10 May 2022.
  3. ^ "perlref". perldoc.perl.org. Retrieved 2025-08-05.
  4. ^ "Variable variables - Manual". PHP. Retrieved 2025-08-05.
[edit]
  • Pointer Fun With Binky Introduction to pointers in a 3-minute educational video – Stanford Computer Science Education Library
羊水穿刺是检查什么 脸色发红什么原因 县纪委副书记什么级别 快闪店是什么意思 怀孕前检查什么项目内容
嗣读什么 结婚55周年是什么婚 脚软没力气是什么原因引起的 心血管科是看什么病 脚踩棉花感见于什么病
神经性皮炎不能吃什么食物 什么情况下会怀孕 毕业花束选什么花 寒热重症是什么病 基数是什么意思
哒哒是什么意思 台湾以前叫什么名字 湖北人喜欢吃什么菜 皮蛋吃了有什么好处和坏处 血压偏低有什么症状
毛很长的狗是什么品种hcv8jop7ns9r.cn 脓疱疮是什么原因引起的hcv8jop1ns5r.cn 保温杯什么牌子好hcv9jop7ns5r.cn 小便憋不住是什么原因hcv8jop2ns8r.cn 减肥吃什么好hcv9jop3ns5r.cn
异位妊娠是什么意思hcv8jop0ns8r.cn 壁是什么意思hcv8jop5ns9r.cn 伏羲是什么意思hcv9jop0ns0r.cn 奥司他韦是什么药hcv9jop2ns6r.cn 为什么打雷闪电hcv7jop5ns6r.cn
杂菌2个加是什么意思hcv8jop2ns0r.cn 耳道湿疹用什么药hcv8jop8ns9r.cn 大s什么病hcv9jop0ns2r.cn 心房颤动是什么意思hcv9jop1ns3r.cn 糖尿病吃什么药hcv9jop5ns0r.cn
饱和脂肪是什么hcv9jop4ns5r.cn 3月份生日是什么星座hcv9jop4ns0r.cn 吃什么水果容易排便hcv8jop2ns0r.cn 胃胀痛吃什么药好hcv8jop5ns2r.cn 蕊字五行属什么hcv7jop5ns2r.cn
百度