资源描述:
《计算机专业毕业论文_论文外文文献中英文翻译(object)》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、word文档整理分享外文资料ObjectlandscapesandlifetimesTechnically,OOPisjustaboutabstractdatatyping,inheritance,andpolymorphism,butotherissuescanbeatleastasimportant.Theremainderofthissectionwillcovertheseissues.Oneofthemostimportantfactorsisthewayobjectsarecreatedanddestroyed
2、.Whereisthedataforanobjectandhowisthelifetimeoftheobjectcontrolled?Therearedifferentphilosophiesatworkhere.C++takestheapproachthatcontrolofefficiencyisthemostimportantissue,soitgivestheprogrammerachoice.Formaximumrun-timespeed,thestorageandlifetimecanbedeterminedw
3、hiletheprogramisbeingwritten,byplacingtheobjectsonthestack(thesearesometimescalledautomaticorscopedvariables)orinthestaticstoragearea.Thisplacesapriorityonthespeedofstorageallocationandrelease,andcontrolofthesecanbeveryvaluableinsomesituations.However,yousacrifice
4、flexibilitybecauseyoumustknowtheexactquantity,lifetime,andtypeofobjectswhileyou'rewritingtheprogram.Ifyouaretryingtosolveamoregeneralproblemsuchascomputer-aideddesign,warehousemanagement,orair-trafficcontrol,thisistoorestrictive.Thesecondapproachistocreateobjectsd
5、ynamicallyinapoolofmemorycalledtheheap.Inthisapproach,youdon'tknowuntilrun-timehowmanyobjectsyouneed,whattheirlifetimeis,orwhattheirexacttypeis.Thosearedeterminedatthespurofthemomentwhiletheprogramisrunning.Ifyouneedanewobject,yousimplymakeitontheheapatthepointtha
6、tyouneedit.Becausethestorageismanageddynamically,atrun-time,theamountoftimerequiredtoallocatestorageontheheapissignificantlylongerthan参考资料word文档整理分享thetimetocreatestorageonthestack.(Creatingstorageonthestackisoftenasingleassemblyinstructiontomovethestackpointerdow
7、n,andanothertomoveitbackup.)Thedynamicapproachmakesthegenerallylogicalassumptionthatobjectstendtobecomplicated,sotheextraoverheadoffindingstorageandreleasingthatstoragewillnothaveanimportantimpactonthecreationofanobject.Inaddition,thegreaterflexibilityisessentialt
8、osolvethegeneralprogrammingproblem.Javausesthesecondapproach,exclusively].Everytimeyouwanttocreateanobject,youusethenewkeywordtobuildadynamicinstanceoft