• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Daly的游戲人生

            資源和內(nèi)存管理學(xué)習(xí)總結(jié)

            整理了手頭上幾本書中關(guān)于資源和內(nèi)存管理的章節(jié)


            <Understanding the linux kenel 第三版> 8.1.7 the buddy system
                Buddy算法, 解決內(nèi)存碎片問題. 張貼書本原文如下:

            The technique adopted by Linux to solve the external fragmentation problem is based on the well-known buddy system algorithm. All free page frames are grouped into 11 lists of blocks that contain groups of 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, and 1024 contiguous page frames, respectively. The largest request of 1024 page frames corresponds to a chunk of 4 MB of contiguous RAM. The physical address of the first page frame of a block is a multiple of the group sizefor example, the initial address of a 16-page-frame block is a multiple of 16 x 212 (212 = 4,096, which is the regular page size).


            We'll show how the algorithm works through a simple example:

            Assume there is a request for a group of 256 contiguous page frames (i.e., one megabyte). The algorithm checks first to see whether a free block in the 256-page-frame list exists. If there is no such block, the algorithm looks for the next larger blocka free block in the 512-page-frame list. If such a block exists, the kernel allocates 256 of the 512 page frames to satisfy the request and inserts the remaining 256 page frames into the list of free 256-page-frame blocks. If there is no free 512-page block, the kernel then looks for the next larger block (i.e., a free 1024-page-frame block). If such a block exists, it allocates 256 of the 1024 page frames to satisfy the request, inserts the first 512 of the remaining 768 page frames into the list of free 512-page-frame blocks, and inserts the last 256 page frames into the list of free 256-page-frame blocks. If the list of 1024-page-frame blocks is empty, the algorithm gives up and signals an error condition.

            The reverse operation, releasing blocks of page frames, gives rise to the name of this algorithm. The kernel attempts to merge pairs of free buddy blocks of size b together into a single block of size 2b. Two blocks are considered buddies if:

            • Both blocks have the same size, say b.

            • They are located in contiguous physical addresses.

            • The physical address of the first page frame of the first block is a multiple of 2 x b x 212.

            The algorithm is iterative; if it succeeds in merging released blocks, it doubles b and tries again so as to create even bigger blocks




            <Modern C++ design 泛型編程與設(shè)計(jì)模式> Chapter 4 small object allocation
                本書討論的是loki庫。第4章探討了小對象的內(nèi)存分配

            <STL源碼解析>  2.2 STL空間分配器  翻譯by 侯捷
                SGI的STL實(shí)現(xiàn)中,allocator的實(shí)現(xiàn)例子。
                二級分配器:大于128byte交給一個(gè)分配器,直接分配內(nèi)存。小數(shù)據(jù)塊交給次級分配器。
                次級分配器用一個(gè)freelist數(shù)組維護(hù)可分配的小塊內(nèi)存區(qū)域。freelist數(shù)組中的項(xiàng)是一個(gè)固定內(nèi)存大小的鏈表。freelist中的項(xiàng)

            這 里用了一個(gè)小技巧(union)
                
            union obj {
                union obj*  free_list_link;
                char client_data[1];
            }
              
                這個(gè)既可用于空閑列表節(jié)點(diǎn),又能作為數(shù)據(jù)指針(強(qiáng)制轉(zhuǎn)換), 這樣就可以節(jié)省信息記錄的空間。
                詳細(xì)說明參考原書


            < 游戲編程精粹1> 1.6 通用的基于句柄的資源管理器

                該文章實(shí)現(xiàn)HandleMgr模板類實(shí)現(xiàn)不同類型資源的管理器.handle為整數(shù)值
                基本思路
            1. vector<DATA>存放實(shí)際數(shù)據(jù), vector儲存magic number, FreeVector儲存數(shù)據(jù)vector中的空閑索引值
            2. Acquire根據(jù) handl值返回?cái)?shù)據(jù)指針(引用計(jì)數(shù)+1), Release釋放data( 引用計(jì)數(shù)減1 )

                技巧1: 利用空結(jié)構(gòu)實(shí)現(xiàn)類型匹配(STL內(nèi)經(jīng)常用這個(gè)技巧)
                    struct tagTexture {}
                    typedef Handle<tagTexture> HTexture
                技巧2:資源釋放時(shí)不需要析構(gòu),只需要把相應(yīng)index加入空閑列表。分配時(shí)重用該對象,重新初始化值,可以提高效率。
                技巧3:一般資源管理器類作為Singleton

                擴(kuò)展1:為標(biāo)準(zhǔn)功能增加自動(dòng)引用計(jì)數(shù)(參考智能指針的實(shí)現(xiàn)?)

            < 游戲編程精粹1> 1.9 基于幀的內(nèi)存分配 by steven ranck
                思路:棧方式(后進(jìn)先出)的內(nèi)存分配器。預(yù)先分配大塊內(nèi)存,然后按棧順序分配和釋放內(nèi)存。
                        僅適用于分配,釋放有嚴(yán)格順序的資源(如關(guān)卡資源)

            <游戲編程精粹1> 1.1
                技巧:所謂的數(shù)據(jù)繼承
                對于不變的對象屬性,具體類用引用指向這些固定屬性,而不是繼承。
                因?yàn)閮H通過對象繼承,每個(gè)對象都有這些固定屬性的拷貝,浪費(fèi)空間。
                Sprite(速度,滿血值,攻擊力) <-- SpriteInstance( 對sprite引用, 位置,當(dāng)前生命值)

            posted on 2010-05-02 00:02 Daly 閱讀(2260) 評論(1)  編輯 收藏 引用 所屬分類: C/C++游戲開發(fā)

            評論

            # re: 資源和內(nèi)存管理學(xué)習(xí)總結(jié) 2010-05-05 08:47 欣萌

            不錯(cuò)。  回復(fù)  更多評論   

            色8激情欧美成人久久综合电| 久久精品这里热有精品| 亚洲精品乱码久久久久久自慰| 国内精品伊人久久久久影院对白| 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲高清不卡 国产成人精品久久亚洲 | 狼狼综合久久久久综合网| 国产ww久久久久久久久久| 国产精品伦理久久久久久| 精品久久久久久久久免费影院 | 久久精品免费网站网| 久久精品亚洲AV久久久无码| 人妻无码中文久久久久专区| 国产精品久久久久久久午夜片| 久久久久av无码免费网| 久久免费高清视频| 激情伊人五月天久久综合| 亚洲精品NV久久久久久久久久| 色综合久久久久综合体桃花网| 久久美女人爽女人爽| 久久久久亚洲av无码专区喷水| 久久久久久青草大香综合精品| 久久精品国产一区二区三区日韩| 97久久精品人妻人人搡人人玩| 久久国产精品成人免费 | 少妇久久久久久被弄高潮| 久久久久夜夜夜精品国产| 国产成人精品久久一区二区三区av | 久久久高清免费视频| 久久香蕉国产线看观看精品yw | 少妇高潮惨叫久久久久久| 亚洲精品国产美女久久久| 久久久中文字幕日本| 午夜精品久久影院蜜桃| 99久久人妻无码精品系列蜜桃| 四虎国产精品免费久久5151| 久久国产色av免费看| 一本一道久久综合狠狠老| 思思久久精品在热线热| 天天爽天天狠久久久综合麻豆| 久久人人爽人人人人片av| 久久综合88熟人妻|