freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

memorypool-資料下載頁(yè)

2025-07-17 15:59本頁(yè)面
  

【正文】 , 0)。 } inline Type* allocate()。 inline bool deallocate(Type*)。 }。 Threadsafety (Using pthread) template typename Type inline Type* mt_MemoryPool::allocate()。 { pthread_mutex_lock(amp。lock)。 Type* ret = ()。 pthread_mutex_unlock(amp。lock)。 return ret。 } Threadsafety (Using pthread) template typename Type inline bool mt_MemoryPool::deallocate(Type* p)。 { pthread_mutex_lock(amp。lock)。 bool ret = (p)。 pthread_mutex_unlock(amp。lock)。 return ret。 } Smart Pointer ? 用類(lèi)似智能指針的思想實(shí)現(xiàn)內(nèi)存池分配空間的自動(dòng)歸還 ? 引用計(jì)數(shù) ? 在智能指針的析構(gòu)中自動(dòng)析構(gòu)對(duì)象并歸還 Smart Pointer void foo() throw(std::runtime_error) { MemoryPoolint::pointer p = ()。 /*statement*/ if ( condition ) throw std::runtime_error(“No memory leak.” )。 /*statement*/ } // p will be executed when leaving this scope Variablesize Memory Pool ?不同于定長(zhǎng)內(nèi)存池,不定長(zhǎng)內(nèi)存池可以在構(gòu)造后申請(qǐng)各種不同大小的內(nèi)存塊。 p = int()。 ?實(shí)現(xiàn)方法:內(nèi)部維護(hù)多個(gè)定長(zhǎng)內(nèi)存池,每次找到最小的能滿(mǎn)足條件的內(nèi)存池進(jìn)行內(nèi)存分配。如果申請(qǐng)的內(nèi)存大于所有的內(nèi)存池大小,則直接調(diào)用 malloc() ?如:分別維護(hù) 1,2,4,8,16,32,64,128,256,512,1024bytes的定長(zhǎng)內(nèi)存池,對(duì)于每一個(gè)內(nèi)存申請(qǐng)向上對(duì)齊到 2的整次冪后分配對(duì)應(yīng)大小的內(nèi)存塊,此時(shí)空間最多浪費(fèi)一倍 ?效率低于定長(zhǎng)內(nèi)存池 Singleton / Static Class ? 強(qiáng)制使類(lèi)只生成一個(gè)實(shí)例。 ? 使用單例模式:將 構(gòu)造 函數(shù)聲明為 private,通過(guò) public函數(shù) GetInstance函數(shù)中的static class reference獲取唯一的實(shí)例 MemoryPoolamp。 pool = MemoryPool::GetInstance()。 ? 靜態(tài) 類(lèi):將類(lèi)的所有函數(shù)聲明為 static,全局靜態(tài)實(shí)例保證唯一性。 p = MemoryPool::allocateint()。 MemoryPool::deallocateint(p)。 Allocator in SGISTL ? 默認(rèn) 使用兩級(jí)配置器 ? 第一級(jí)配置器直接調(diào)用 C的內(nèi)存分配函數(shù) malloc()及 realloc(),如果調(diào)用失敗則執(zhí)行 oom_malloc() ? 第二級(jí)配置 器的做法是,如果區(qū)塊夠大,超過(guò) 128bytes時(shí),就移交第一級(jí)配置器處理。當(dāng)區(qū)塊小于 128bytes時(shí),則以不定長(zhǎng)內(nèi)存池管理。 ? 不定 長(zhǎng)內(nèi)存池中維護(hù) 16個(gè)定長(zhǎng)內(nèi)存池,大小分別為8,16,24,32,40,48,56,64,72,80,88,96,104,112,120,128bytes,將所需的內(nèi)存向上對(duì)齊至 8的倍數(shù)后交由對(duì)應(yīng)的定長(zhǎng)內(nèi)存池分配 ? 所有 stl容器默認(rèn)使用上述 stl::alloc進(jìn)行內(nèi)存管理 Reference ? Stanley , Josee Lajoie, Barbara E. Moo C++ Primer[M] AddisonWesley Educational Publishers Inc, ? 候捷 STL源碼 剖析 [M] 華中科技大學(xué)出版社 , ? SGI SGI STL Allocator Design [G/OL] from: ? Wikipedia Memory Pool [G/OL], from:
點(diǎn)擊復(fù)制文檔內(nèi)容
法律信息相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1