<span id="plx27"><var id="plx27"></var></span>
<dfn id="plx27"><var id="plx27"></var></dfn>
  • <span id="plx27"><code id="plx27"><input id="plx27"></input></code></span>
    <menu id="plx27"></menu><menuitem id="plx27"><thead id="plx27"><input id="plx27"></input></thead></menuitem>
  • <label id="plx27"><code id="plx27"></code></label>
    <label id="plx27"><button id="plx27"></button></label>
  • 歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
    裝配圖網(wǎng)
    ImageVerifierCode 換一換
    首頁 裝配圖網(wǎng) > 資源分類 > PPT文檔下載  

    編譯原理-全動(dòng)態(tài)內(nèi)存管理

    • 資源ID:248239631       資源大?。?span id="pga2tkd" class="font-tahoma">64.50KB        全文頁數(shù):27頁
    • 資源格式: PPT        下載積分:16積分
    快捷下載 游客一鍵下載
    會(huì)員登錄下載
    微信登錄下載
    三方登錄下載: 微信開放平臺(tái)登錄 支付寶登錄   QQ登錄   微博登錄  
    二維碼
    微信掃一掃登錄
    下載資源需要16積分
    郵箱/手機(jī):
    溫馨提示:
    用戶名和密碼都是您填寫的郵箱或者手機(jī)號(hào),方便查詢和重復(fù)下載(系統(tǒng)自動(dòng)生成)
    支付方式: 支付寶    微信支付   
    驗(yàn)證碼:   換一換

     
    賬號(hào):
    密碼:
    驗(yàn)證碼:   換一換
      忘記密碼?
        
    友情提示
    2、PDF文件下載后,可能會(huì)被瀏覽器默認(rèn)打開,此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
    3、本站不支持迅雷下載,請(qǐng)使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
    4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
    5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請(qǐng)知曉。

    編譯原理-全動(dòng)態(tài)內(nèi)存管理

    Click to edit Master title style,Click to edit Master text styles,Second level,Third level,Fourth level,Fifth level,*,Compiler Theory Fall 2003 Jianhui Yue,*,Chapter 7,Dynamic Memory,Parameter Passing Mechanisms,Instructor Jianhui Yue,Software College SCU,compilerscu21cn,Limitations of Stack-Based Environment,If a reference to a local variable in a procedure can be returned to the caller, the result will be dangling reference.,When the procedure is exited, the activation record will be deallocated from the stack.,addr = dangle(),causes,addr,to point to an unsafe location.,Such program is erroneous in C.,(No compiler will give an error message),int *dangle(),int x;,return ,Limitations of Stack-Based Environment (cont),C prohibits local procedures.,Functional programming languages (LISP, ML),Functions must be able to be,locally defined,Passed as parameters,Returned as results.,Stack-based runtime environment is inadequate for these languages.,Fully Dynamic Environment,It can deallocate activation records only when all references to them have disappeared.,Activation records can be dynamically freed at arbitrary times during execution.,Fully dynamic environment is more complicated.,Tracking the references during execution.,Finding and deallocating inaccessible areas of memory at arbitrary times during execution (garbage collection).,Activation Records,The basic structure of an activation record remains the same:,Space for parameters and local variables.,Control and access links.,The exited activation record remains in memory, to be deallocated at some later time.,The entire additional complexity can be encapsulated in a memory manager that replaces the runtime stack operations with more general allocation and deallocation routines.,Object-Oriented Languages,OO languages require special mechanisms in the runtime environment to implement their added features:,Objects,Methods,Inheritance,Dynamic binding,OO languages vary in their requirements for the runtime environment:,C+ retains the stack-based environment of C, no automatic dynamic memory management,Smalltalk requires fully dynamic environment similar to LISP,Implementation of Objects,Keep a complete description of the class structure in memory during execution.,Maintain the inheritance by the superclass pointers.,Keep pointers to all methods.,Each object keeps:,Fields for instance variables,A pointer to its defining class,All methods (local and inherited) are found through it.,Instance variables have predictable offsets.,Methods do not. They are maintained in a symbol table structure with lookup capabilities.,Implementation of Objects (cont),An alternative approach is to compute a list of code pointers for methods of each class, and store this in (static) memory as a virtual function table.,It can be arranged so that each method has a predictable offset.,Each object contains a pointer to the appropriate,virtual function table,.,It is the method of choice for C+.,Example 7.8,class A, public:,double x, y;,void f();,virtual void g();,;,class B: public A, public:,double z;,void f();,virtual void h();,;,x,y,Virtual function table pointer,A:g,x,y,Virtual function table pointer,z,A:g,B:h,Object A,Object B,Heap,The data structure that handles pointer allocation and deallocation is called heap.,Heap is usually allocated as a linear block of memory in a way that it can grow, while interfering as little as possible with the stack.,Heap provides to operation,Allocate,Takes size parameter,Return a pointer to a block of memory of the correct size or null if none exists.,Free,Takes a pointer to an allocated block of memory,Marks it as being free,Must be able to find the size of the block.,Heap Implementation,Use circular linked list of free blocks.,Two drawbacks:,Free operation cannot tell whether its pointer is pointing at a block of memory that was previously allocated by,malloc,.,Need to,coalesce,blocks to the adjacent free blocks. The result is a free block of the maximal size.,This needs to be done to avoid the fragmentation.,Improved Heap Implementation,1 Tow improvements ( more robust , self-coalescing blocks ),Bookkeeping information : Header,(next : pointer to the next block in the list ,usedsize , freesize ),Free space pointer :memptr,( point to the block hold free space ),next,usedsize,freesize,used space,free space,header,malloc and free operation on heap,allocated header,free space,used,used,used,free,memptr,used,free,used,free,memptr,a,b,c,a : initialized b: 3 times malloc operations c free one block,memptr,malloc ( nbytes),Header *p ,*newp; unsigned nunits;,nunits= ( nbytes+sizeof(Header)-1)/sizeof(Header ) + 1;,/* initiate the first header */,/* search the list with the first fit , the p points to the first fit block */,newp=p+p->s.usedsized ;,newp ->used= nunits;,newp ->s.freesize=p->s.freesize-nunits;,newp->s.next=p->s.next;,p->s.freesize=0;,p->s.next=newp;,memptr=newp;,return (void *) (newp+1);,free ( void *ap ), Header *bp,*p,*prev;,bp= (Header *) ap 1;,/* search the list to find the block containing ap */,prev->s.freesize+=p->s.usedsize+p->s.freesize;,prev->s.next=p->s.next;,memptr=prev;,Automatic Management of Heap,The programmer uses the explicit management on the heap using manually malloc( ) and free( ).,In the fully dynamic runtime environment, the heap should be managed automatically.,malloc,can be automatically scheduled at each procedure call.,free,cannot be automatically scheduled on exit,Activation records must persist until all references to them have disappeared.,Mark and Sweep,The standard technique is,mark and sweep garbage collection,.,No memory is freed until the call to,malloc,fails.,Follow all pointer recursively and mark each block of storage reached.,Sweep linearly through the memory, return unmarked blocks to free memory.,Memory compaction by moving all the allocated space to one end of the heap,Drawbacks,Extra storage for marks,Delay in processing (minutes) due to multiple passes.,Parameter Passing Mechanisms,Parameters correspond the to locations in the activation record, which are filled with parameter values (arguments).,To the called procedure, a parameter represents a pure formal value. It serves to establish a location in the activation record, where the procedure can find the value of the parameter.,Common Parameter Passing Mechanisms,Pass by value,Pass by reference,Pass by value-result,Pass by name (delayed evaluation),Parameter Evaluation Order,In most situations, the order in which arguments are evaluated is unimportant. Any evaluation order will produce the same result.,It is not true in general.,f(+x, x),A standard evaluation order may be specified,By the language definition,By a compiler writer (different implementations),C compilers typically evaluate their arguments from right to left.,Pass by Value,This is the only parameter passing mechanism available in C.,The parameters in the body of the procedure are replaced by the values of the arguments.,In C, value parameters are viewed as initialized local variables.,Changes to them never cause any nonlocal changes.,void inc2(int x), +x; +x; /* incorrect */,void inc2(int* x), +x; +x; /* correct */,inc2(,Pass by Reference,Pass by reference passes the location of the variable, so that the parameter becomes an alias for the argument.,Any changes made to parameter occur to the argument as well.,This is the only parameter passing in FORTRAN77.,void inc2(int & x), +x; +x; /* correct */,inc2(y);,Pass by Reference (cont),The compiler must,Compute the address of the argument,Store it in the local activation record,Turn local accesses to a reference parameter into indirect accesses,No copy of the passed value is made.,This is significant when the parameter is a large structure.,Pass by Value-Result,Similar to pass by reference.,No actual alias is established,The value of the argument is copied and used in the procedure,On exit the final value of the parameter is copied back out to the location of the argument.,This method is known as copy-in, copy-out or copy-restore.,void p(int x, int y), +x; +y;,main (), int a=1;,p(a,a);,return 0;,a,has value of,3,after,p,is called if pass by reference is used.,a,has value of,2,after,p,is called if pass by value-result is used.,Pass by Name,The idea is that the argument is not evaluated until its actual use in the called program.,The name of the argument replaces the name of the parameter it corresponds to.,int i;,int a10,void p(int x), +i; +x;,main(), i=1;,a1=1;,a2=2,p(ai);,return 0; ,a2,is set to 3,a1,is unchanged,Pass by Name (cont),Pass by name was offered in,Algol60, but become unpopular.,It can give surprising and counterintuitive results in the presence of the side effects.,It is difficult to implement,Each argument must be turned into the procedure,It is inefficient,A variation on this mechanism called,lazy evaluation,become popular in purely functional languages,(Miranda, Haskell),Homework,7.11, 7.15,

    注意事項(xiàng)

    本文(編譯原理-全動(dòng)態(tài)內(nèi)存管理)為本站會(huì)員(e****s)主動(dòng)上傳,裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

    溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請(qǐng)重新下載,重復(fù)下載不扣分。




    關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

    copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

    備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


    本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!

    欧美久久久一区二区三区,国产精品亚洲一区二区无码,亚洲国产精品综合久久20声音,亚洲国产精品无码久久久蜜芽
    <span id="plx27"><var id="plx27"></var></span>
    <dfn id="plx27"><var id="plx27"></var></dfn>
  • <span id="plx27"><code id="plx27"><input id="plx27"></input></code></span>
    <menu id="plx27"></menu><menuitem id="plx27"><thead id="plx27"><input id="plx27"></input></thead></menuitem>
  • <label id="plx27"><code id="plx27"></code></label>
    <label id="plx27"><button id="plx27"></button></label>