网络即时通信系统的设计 外文文献翻译.doc

上传人:b****9 文档编号:93957 上传时间:2022-10-02 格式:DOC 页数:13 大小:59.50KB
下载 相关 举报
网络即时通信系统的设计 外文文献翻译.doc_第1页
第1页 / 共13页
网络即时通信系统的设计 外文文献翻译.doc_第2页
第2页 / 共13页
网络即时通信系统的设计 外文文献翻译.doc_第3页
第3页 / 共13页
网络即时通信系统的设计 外文文献翻译.doc_第4页
第4页 / 共13页
网络即时通信系统的设计 外文文献翻译.doc_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

网络即时通信系统的设计 外文文献翻译.doc

《网络即时通信系统的设计 外文文献翻译.doc》由会员分享,可在线阅读,更多相关《网络即时通信系统的设计 外文文献翻译.doc(13页珍藏版)》请在冰豆网上搜索。

网络即时通信系统的设计 外文文献翻译.doc

学校代码:

XXX

学号:

XXX

本科毕业设计外文文献翻译

学生姓名:

XXX

学院:

信息工程学院

系别:

计算机系

专业:

软件工程

班级:

软件06

指导教师:

XXX讲师

     

二○一○年六月

本文源码索取,请联系qq:

XXX工业大学本科毕业设计外文文献翻译

Objectlandscapesandlifetimes

Technically,OOPisjustaboutabstractdatatyping,inheritance,andpolymorphism,butotherissuescanbeatleastasimportant.Theremainderofthissectionwillcovertheseissues.

Oneofthemostimportantfactorsisthewayobjectsarecreatedanddestroyed.Whereisthedataforanobjectandhowisthelifetimeoftheobjectcontrolled?

Therearedifferentphilosophiesatworkhere.C++takestheapproachthatcontrolofefficiencyisthemostimportantissue,soitgivestheprogrammerachoice.Formaximumrun-timespeed,thestorageandlifetimecanbedeterminedwhiletheprogramisbeingwritten,byplacingtheobjectsonthestack(thesearesometimescalledautomaticorscopedvariables)orinthestaticstoragearea.Thisplacesapriorityonthespeedofstorageallocationandrelease,andcontrolofthesecanbeveryvaluableinsomesituations.However,yousacrificeflexibilitybecauseyoumustknowtheexactquantity,lifetime,andtypeofobjectswhileyou'rewritingtheprogram.Ifyouaretryingtosolveamoregeneralproblemsuchascomputer-aideddesign,warehousemanagement,orair-trafficcontrol,thisistoorestrictive.

Thesecondapproachistocreateobjectsdynamicallyinapoolofmemorycalledtheheap.Inthisapproach,youdon'tknowuntilrun-timehowmanyobjectsyouneed,whattheirlifetimeis,orwhattheirexacttypeis.Thosearedeterminedatthespurofthemomentwhiletheprogramisrunning.Ifyouneedanewobject,yousimplymakeitontheheapatthepointthatyouneedit.Becausethestorageismanageddynamically,atrun-time,theamountoftimerequiredtoallocatestorageontheheapissignificantlylongerthanthetimetocreatestorageonthestack.(Creatingstorageonthestackisoftenasingleassemblyinstructiontomovethestackpointerdown,andanothertomoveitbackup.)Thedynamicapproachmakesthegenerallylogicalassumptionthatobjectstendtobecomplicated,sotheextraoverheadoffindingstorageandreleasingthatstoragewillnothaveanimportantimpactonthecreationofanobject.Inaddition,thegreaterflexibilityisessentialtosolvethegeneralprogrammingproblem.

Javausesthesecondapproach,exclusively].Everytimeyouwanttocreateanobject,youusethenewkeywordtobuildadynamicinstanceofthatobject.

There'sanotherissue,however,andthat'sthelifetimeofanobject.Withlanguagesthatallowobjectstobecreatedonthestack,thecompilerdetermineshowlongtheobjectlastsandcanautomaticallydestroyit.However,ifyoucreateitontheheapthecompilerhasnoknowledgeofitslifetime.InalanguagelikeC++,youmustdetermineprogrammaticallywhentodestroytheobject,whichcanleadtomemoryleaksifyoudon’tdoitcorrectly(andthisisacommonprobleminC++programs).Javaprovidesafeaturecalledagarbagecollectorthatautomaticallydiscoverswhenanobjectisnolongerinuseanddestroysit.Agarbagecollectorismuchmoreconvenientbecauseitreducesthenumberofissuesthatyoumusttrackandthecodeyoumustwrite.Moreimportant,thegarbagecollectorprovidesamuchhigherlevelofinsuranceagainsttheinsidiousproblemofmemoryleaks(whichhasbroughtmanyaC++projecttoitsknees).

Therestofthissectionlooksatadditionalfactorsconcerningobjectlifetimesandlandscapes.

1Collectionsanditerators

Ifyoudon’tknowhowmanyobjectsyou’regoingtoneedtosolveaparticularproblem,orhowlongtheywilllast,youalsodon’tknowhowtostorethoseobjects.Howcanyouknowhowmuchspacetocreateforthoseobjects?

Youcan’t,sincethatinformationisn’tknownuntilrun-time.

Thesolutiontomostproblemsinobject-orienteddesignseemsflippant:

youcreateanothertypeofobject.Thenewtypeofobjectthatsolvesthisparticularproblemholdsreferencestootherobjects.Ofcourse,youcandothesamethingwithanarray,whichisavailableinmostlanguages.Butthere’smore.Thisnewobject,generallycalledacontainer(alsocalledacollection,buttheJavalibraryusesthatterminadifferentsensesothisbookwilluse“container”),willexpanditselfwhenevernecessarytoaccommodateeverythingyouplaceinsideit.Soyoudon’tneedtoknowhowmanyobjectsyou’regoingtoholdinacontainer.Justcreateacontainerobjectandletittakecareofthedetails.

Fortunately,agoodOOPlanguagecomeswithasetofcontainersaspartofthepackage.InC++,it’spartoftheStandardC++LibraryandissometimescalledtheStandardTemplateLibrary(STL).ObjectPascalhascontainersinitsVisualComponentLibrary(VCL).Smalltalkhasaverycompletesetofcon

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1