計(jì)算機(jī)畢業(yè)論文中英對(duì)照外文翻譯——對(duì)象的創(chuàng)建和存在時(shí)間.doc
約13頁(yè)DOC格式手機(jī)打開展開
計(jì)算機(jī)畢業(yè)論文中英對(duì)照外文翻譯——對(duì)象的創(chuàng)建和存在時(shí)間,technically, oop is just about abstract data typing, inheritance, and polymorphism, but other issues can be at least as important. the remainder of this section...
內(nèi)容介紹
此文檔由會(huì)員 wanli1988go 發(fā)布
Technically, OOP is just about abstract data typing, inheritance, and polymorphism, but other issues can be at least as important. The remainder of this section will cover these issues.
One of the most important factors is the way objects are created and destroyed. Where is the data for an object and how is the lifetime of the object controlled? There are different philosophies at work here. C++ takes the approach that control of efficiency is the most important issue, so it gives the programmer a choice. For maximum run-time speed, the storage and lifetime can be determined while the program is being written, by placing the objects on the stack (these are sometimes called automatic or scoped variables) or in the static storage area. This places a priority on the speed of storage allocation and release, and control of these can be very valuable in some situations. However, you sacrifice flexibility because you must know the exact quantity, lifetime, and type of objects while you're writing the program. If you are trying to solve a more general problem such as computer-aided design, warehouse management, or air-traffic control, this is too restrictive.
The second approach is to create objects dynamically in a pool of memory called the heap. In this approach, you don't know until run-time how many objects you need, what their lifetime is, or what their exact type is. Those are determined at the spur of the moment while the program is running. If you need a new object, you simply make it on the heap at the point that you need it. Because the storage is managed dynamically, at run-time, the amount of time required to allocate storage on the heap is significantly longer than the time to create storage on the stack. (Creating storage on the stack is often a single assembly instruction to move the stack pointer down, and another to move it back up.) The dynamic approach makes the generally logical assumption that objects tend to be complicated, so the extra overhead of finding storage and releasing that storage will not have an important impact on the creation of an object. In addition, the greater flexibility is essential to solve the general
從技術(shù)角度說,OOP(面向?qū)ο蟪绦蛟O(shè)計(jì))只是涉及抽象的數(shù)據(jù)類型、繼承以及多形性,但另一些問題也可能顯得非常重要。本節(jié)將就這些問題進(jìn)行探討。
最重要的問題之一是對(duì)象的創(chuàng)建及破壞方式。對(duì)象需要的數(shù)據(jù)位于哪兒,如何控制對(duì)象的“存在時(shí)間”呢?針對(duì)這個(gè)問題,解決的方案是各異其趣的。C++認(rèn)為程序的執(zhí)行效率是最重要的一個(gè)問題,所以它允許程序員作出選擇。為獲得最快的運(yùn)行速度,存儲(chǔ)以及存在時(shí)間可在編寫程序時(shí)決定,只需將對(duì)象放置在堆棧(有時(shí)也叫作自動(dòng)或定域變量)或者靜態(tài)存儲(chǔ)區(qū)域即可。這樣便為存儲(chǔ)空間的分配和釋放提供了一個(gè)優(yōu)先級(jí)。某些情況下,這種優(yōu)先級(jí)的控制是非常有價(jià)值的。然而,我們同時(shí)也犧牲了靈活性,因?yàn)樵诰帉懗绦驎r(shí),必須知道對(duì)象的準(zhǔn)確的數(shù)量、存在時(shí)間、以及類型。如果要解決的是一個(gè)較常規(guī)的問題,如計(jì)算機(jī)輔助設(shè)計(jì)、倉(cāng)儲(chǔ)管理或者空中交通控制,這一方法就顯得太局限了。
第二個(gè)方法是在一個(gè)內(nèi)存池中動(dòng)態(tài)創(chuàng)建對(duì)象,該內(nèi)存池亦叫“堆”或者“內(nèi)存堆”。若采用這種方式,除非進(jìn)入運(yùn)行期,否則根本不知道到底需要多少個(gè)對(duì)象,也不知道它們的存在時(shí)間有多長(zhǎng),以及準(zhǔn)確的類型是什么。這些參數(shù)都在程序正式運(yùn)行時(shí)才決定的。若需一個(gè)新對(duì)象,只需在需要它的時(shí)候在內(nèi)存堆里簡(jiǎn)單地創(chuàng)建它即可。由于存儲(chǔ)空間的管理是運(yùn)行期間動(dòng)態(tài)進(jìn)行的,所以在內(nèi)存堆里分配存儲(chǔ)空間的時(shí)間比在堆棧里創(chuàng)建的時(shí)間長(zhǎng)得多(在堆棧里創(chuàng)建存儲(chǔ)空間一般只需要一個(gè)簡(jiǎn)單的指令,將堆棧指針向下或向下移動(dòng)即可)。由于動(dòng)態(tài)創(chuàng)建方法使對(duì)象本來(lái)就傾向于復(fù)雜,所以查找存儲(chǔ)空間以及釋放它所需的額外開銷不會(huì)為對(duì)象的創(chuàng)建造成明顯的影響。除此以外,更大的靈活性對(duì)于常規(guī)編程問題的解決是至關(guān)重要的。
C++允許我們決定是在寫程序時(shí)創(chuàng)建對(duì)象,還是在運(yùn)行期間創(chuàng)建,這種控制方法更加靈活。大家或許認(rèn)為既然它如此靈活,那么無(wú)論如何都應(yīng)在內(nèi)存堆里創(chuàng)建對(duì)象,而不是在堆棧中創(chuàng)建。
但還要考慮另外一個(gè)問題,亦即對(duì)象的“存在時(shí)間”或者“生存時(shí)間”(Lifetime)。若在堆?;蛘哽o態(tài)存儲(chǔ)空間里創(chuàng)建一個(gè)對(duì)象,編譯器會(huì)判斷對(duì)象的持續(xù)時(shí)間有多長(zhǎng),到時(shí)會(huì)自動(dòng)“破壞”或者“清除”它。程序員可用兩種方法來(lái)破壞一個(gè)對(duì)象:用程序化的方式?jīng)Q定何時(shí)破壞對(duì)象,或者利用由運(yùn)行環(huán)境提供的一種“垃圾收集器”特性,自動(dòng)尋找那些不再使用的對(duì)象,并將其清除。當(dāng)然,垃圾收集器顯得方便得多,但要求所有應(yīng)用程序都必須容忍垃圾收集器的存在,并能默許隨垃圾收集帶來(lái)的額外開銷。但這并不符合C++語(yǔ)言的設(shè)計(jì)宗旨,所以未能包括到C++里。但Java確實(shí)提供了一個(gè)垃圾收集器(Smalltalk也有這樣的設(shè)計(jì);盡管Delphi默認(rèn)為沒有垃圾收集器,但可選擇安裝;而C++亦可使用一些由其他公司開發(fā)的垃圾收集產(chǎn)品)。
本節(jié)剩下的部分將討論操縱對(duì)象時(shí)要考慮的另一些因素。
One of the most important factors is the way objects are created and destroyed. Where is the data for an object and how is the lifetime of the object controlled? There are different philosophies at work here. C++ takes the approach that control of efficiency is the most important issue, so it gives the programmer a choice. For maximum run-time speed, the storage and lifetime can be determined while the program is being written, by placing the objects on the stack (these are sometimes called automatic or scoped variables) or in the static storage area. This places a priority on the speed of storage allocation and release, and control of these can be very valuable in some situations. However, you sacrifice flexibility because you must know the exact quantity, lifetime, and type of objects while you're writing the program. If you are trying to solve a more general problem such as computer-aided design, warehouse management, or air-traffic control, this is too restrictive.
The second approach is to create objects dynamically in a pool of memory called the heap. In this approach, you don't know until run-time how many objects you need, what their lifetime is, or what their exact type is. Those are determined at the spur of the moment while the program is running. If you need a new object, you simply make it on the heap at the point that you need it. Because the storage is managed dynamically, at run-time, the amount of time required to allocate storage on the heap is significantly longer than the time to create storage on the stack. (Creating storage on the stack is often a single assembly instruction to move the stack pointer down, and another to move it back up.) The dynamic approach makes the generally logical assumption that objects tend to be complicated, so the extra overhead of finding storage and releasing that storage will not have an important impact on the creation of an object. In addition, the greater flexibility is essential to solve the general
從技術(shù)角度說,OOP(面向?qū)ο蟪绦蛟O(shè)計(jì))只是涉及抽象的數(shù)據(jù)類型、繼承以及多形性,但另一些問題也可能顯得非常重要。本節(jié)將就這些問題進(jìn)行探討。
最重要的問題之一是對(duì)象的創(chuàng)建及破壞方式。對(duì)象需要的數(shù)據(jù)位于哪兒,如何控制對(duì)象的“存在時(shí)間”呢?針對(duì)這個(gè)問題,解決的方案是各異其趣的。C++認(rèn)為程序的執(zhí)行效率是最重要的一個(gè)問題,所以它允許程序員作出選擇。為獲得最快的運(yùn)行速度,存儲(chǔ)以及存在時(shí)間可在編寫程序時(shí)決定,只需將對(duì)象放置在堆棧(有時(shí)也叫作自動(dòng)或定域變量)或者靜態(tài)存儲(chǔ)區(qū)域即可。這樣便為存儲(chǔ)空間的分配和釋放提供了一個(gè)優(yōu)先級(jí)。某些情況下,這種優(yōu)先級(jí)的控制是非常有價(jià)值的。然而,我們同時(shí)也犧牲了靈活性,因?yàn)樵诰帉懗绦驎r(shí),必須知道對(duì)象的準(zhǔn)確的數(shù)量、存在時(shí)間、以及類型。如果要解決的是一個(gè)較常規(guī)的問題,如計(jì)算機(jī)輔助設(shè)計(jì)、倉(cāng)儲(chǔ)管理或者空中交通控制,這一方法就顯得太局限了。
第二個(gè)方法是在一個(gè)內(nèi)存池中動(dòng)態(tài)創(chuàng)建對(duì)象,該內(nèi)存池亦叫“堆”或者“內(nèi)存堆”。若采用這種方式,除非進(jìn)入運(yùn)行期,否則根本不知道到底需要多少個(gè)對(duì)象,也不知道它們的存在時(shí)間有多長(zhǎng),以及準(zhǔn)確的類型是什么。這些參數(shù)都在程序正式運(yùn)行時(shí)才決定的。若需一個(gè)新對(duì)象,只需在需要它的時(shí)候在內(nèi)存堆里簡(jiǎn)單地創(chuàng)建它即可。由于存儲(chǔ)空間的管理是運(yùn)行期間動(dòng)態(tài)進(jìn)行的,所以在內(nèi)存堆里分配存儲(chǔ)空間的時(shí)間比在堆棧里創(chuàng)建的時(shí)間長(zhǎng)得多(在堆棧里創(chuàng)建存儲(chǔ)空間一般只需要一個(gè)簡(jiǎn)單的指令,將堆棧指針向下或向下移動(dòng)即可)。由于動(dòng)態(tài)創(chuàng)建方法使對(duì)象本來(lái)就傾向于復(fù)雜,所以查找存儲(chǔ)空間以及釋放它所需的額外開銷不會(huì)為對(duì)象的創(chuàng)建造成明顯的影響。除此以外,更大的靈活性對(duì)于常規(guī)編程問題的解決是至關(guān)重要的。
C++允許我們決定是在寫程序時(shí)創(chuàng)建對(duì)象,還是在運(yùn)行期間創(chuàng)建,這種控制方法更加靈活。大家或許認(rèn)為既然它如此靈活,那么無(wú)論如何都應(yīng)在內(nèi)存堆里創(chuàng)建對(duì)象,而不是在堆棧中創(chuàng)建。
但還要考慮另外一個(gè)問題,亦即對(duì)象的“存在時(shí)間”或者“生存時(shí)間”(Lifetime)。若在堆?;蛘哽o態(tài)存儲(chǔ)空間里創(chuàng)建一個(gè)對(duì)象,編譯器會(huì)判斷對(duì)象的持續(xù)時(shí)間有多長(zhǎng),到時(shí)會(huì)自動(dòng)“破壞”或者“清除”它。程序員可用兩種方法來(lái)破壞一個(gè)對(duì)象:用程序化的方式?jīng)Q定何時(shí)破壞對(duì)象,或者利用由運(yùn)行環(huán)境提供的一種“垃圾收集器”特性,自動(dòng)尋找那些不再使用的對(duì)象,并將其清除。當(dāng)然,垃圾收集器顯得方便得多,但要求所有應(yīng)用程序都必須容忍垃圾收集器的存在,并能默許隨垃圾收集帶來(lái)的額外開銷。但這并不符合C++語(yǔ)言的設(shè)計(jì)宗旨,所以未能包括到C++里。但Java確實(shí)提供了一個(gè)垃圾收集器(Smalltalk也有這樣的設(shè)計(jì);盡管Delphi默認(rèn)為沒有垃圾收集器,但可選擇安裝;而C++亦可使用一些由其他公司開發(fā)的垃圾收集產(chǎn)品)。
本節(jié)剩下的部分將討論操縱對(duì)象時(shí)要考慮的另一些因素。
TA們正在看...
- 《萬(wàn)以內(nèi)數(shù)連加》ppt課件(北京市縣級(jí)優(yōu)課).ppt
- 《九.收集數(shù)據(jù)》ppt課件(北京市縣級(jí)優(yōu)課).pptx
- 《九.收集數(shù)據(jù)》ppt課件(安徽省縣級(jí)優(yōu)課).ppt
- 《九.收集數(shù)據(jù)》ppt課件(湖北省縣級(jí)優(yōu)課).pptx
- 《九.收集數(shù)據(jù)》ppt課件(陜西省縣級(jí)優(yōu)課).ppt
- 《八.時(shí).分.秒的認(rèn)識(shí)》ppt課件(北京市縣級(jí)優(yōu)課).ppt
- 《八.時(shí).分.秒的認(rèn)識(shí)》ppt課件(北京市省級(jí)優(yōu)課).ppt
- 《八.時(shí).分.秒的認(rèn)識(shí)》ppt課件(吉林省縣級(jí)優(yōu)課).pp...pptx
- 《八.時(shí).分.秒的認(rèn)識(shí)》ppt課件(吉林省市級(jí)優(yōu)課).ppt
- 《八.時(shí).分.秒的認(rèn)識(shí)》ppt課件(安徽省縣級(jí)優(yōu)課).pp...pptx