cocos2dx多线程以及线程同步 与 cocos2dx内存管理与多线程问题
//-------------------------------------------------------------------- // // CCPoolManager // //-------------------------------------------------------------------- /////【diff - begin】- by layne////// CCPoolManager* CCPoolManager::shared
//--------------------------------------------------------------------
//
// CCPoolManager
//
//--------------------------------------------------------------------
/////【diff - begin】- by layne//////
CCPoolManager* CCPoolManager::sharedPoolManager()
{
if (s_pPoolManager == NULL)
{
s_pPoolManager = new CCPoolManager();
}
return s_pPoolManager;
}
void CCPoolManager::purgePoolManager()
{
CC_SAFE_DELETE(s_pPoolManager);
}
CCPoolManager::CCPoolManager()
{
// m_pReleasePoolStack = new CCArray();
// m_pReleasePoolStack->init();
// m_pCurReleasePool = 0;
m_pReleasePoolMultiStack = new CCDictionary();
}
CCPoolManager::~CCPoolManager()
{
// finalize();
// // we only release the last autorelease pool here
// m_pCurReleasePool = 0;
// m_pReleasePoolStack->removeObjectAtIndex(0);
//
// CC_SAFE_DELETE(m_pReleasePoolStack);
finalize();
CC_SAFE_DELETE(m_pReleasePoolMultiStack);
}
void CCPoolManager::finalize()
{
if(m_pReleasePoolMultiStack->count() > 0)
{
//CCAutoreleasePool* pReleasePool;
CCObject* pkey = NULL;
CCARRAY_FOREACH(m_pReleasePoolMultiStack->allKeys(), pkey)
{
if(!pkey)
break;
CCInteger *key = (CCInteger*)pkey;
CCArray *poolStack = (CCArray *)m_pReleasePoolMultiStack->objectForKey(key->getValue());
CCObject* pObj = NULL;
CCARRAY_FOREACH(poolStack, pObj)
{
if(!pObj)
break;
CCAutoreleasePool* pPool = (CCAutoreleasePool*)pObj;
pPool->clear();
}
}
}
}
void CCPoolManager::push()
{
// CCAutoreleasePool* pPool = new CCAutoreleasePool(); //ref = 1
// m_pCurReleasePool = pPool;
//
// m_pReleasePoolStack->addObject(pPool); //ref = 2
//
// pPool->release(); //ref = 1
pthread_mutex_lock(&m_mutex);
CCArray* pCurReleasePoolStack = getCurReleasePoolStack();
CCAutoreleasePool* pPool = new CCAutoreleasePool(); //ref = 1
pCurReleasePoolStack->addObject(pPool); //ref = 2
pPool->release(); //ref = 1
pthread_mutex_unlock(&m_mutex);
}
void CCPoolManager::pop()
{
// if (! m_pCurReleasePool)
// {
// return;
// }
//
// int nCount = m_pReleasePoolStack->count();
//
// m_pCurReleasePool->clear();
//
// if(nCount > 1)
// {
// m_pReleasePoolStack->removeObjectAtIndex(nCount-1);
//
// // if(nCount > 1)
// // {
// // m_pCurReleasePool = m_pReleasePoolStack->objectAtIndex(nCount - 2);
// // return;
// // }
// m_pCurReleasePool = (CCAutoreleasePool*)m_pReleasePoolStack->objectAtIndex(nCount - 2);
// }
//
// /*m_pCurReleasePool = NULL;*/
pthread_mutex_lock(&m_mutex);
CCArray* pCurReleasePoolStack = getCurReleasePoolStack();
CCAutoreleasePool* pCurReleasePool = getCurReleasePool();
if (pCurReleasePoolStack && pCurReleasePool)
{
int nCount = pCurReleasePoolStack->count();
pCurReleasePool->clear();
if(nCount > 1)
{
pCurReleasePoolStack->removeObject(pCurReleasePool);
}
}
pthread_mutex_unlock(&m_mutex);
}
void CCPoolManager::removeObject(CCObject* pObject)
{
// CCAssert(m_pCurReleasePool, "current auto release pool should not be null");
//
// m_pCurReleasePool->removeObject(pObject);
pthread_mutex_lock(&m_mutex);
CCAutoreleasePool* pCurReleasePool = getCurReleasePool();
CCAssert(pCurReleasePool, "current auto release pool should not be null");
pCurReleasePool->removeObject(pObject);
pthread_mutex_unlock(&m_mutex);
}
void CCPoolManager::addObject(CCObject* pObject)
{
// getCurReleasePool()->addObject(pObject);
pthread_mutex_lock(&m_mutex);
CCAutoreleasePool* pCurReleasePool = getCurReleasePool(true);
CCAssert(pCurReleasePool, "current auto release pool should not be null");
pCurReleasePool->addObject(pObject);
pthread_mutex_unlock(&m_mutex);
}
CCArray* CCPoolManager::getCurReleasePoolStack()
{
CCArray* pPoolStack = NULL;
pthread_t tid = pthread_self();
if(m_pReleasePoolMultiStack->count() > 0)
{
pPoolStack = (CCArray*)m_pReleasePoolMultiStack->objectForKey((int)tid);
}
if (!pPoolStack) {
pPoolStack = new CCArray();
m_pReleasePoolMultiStack->setObject(pPoolStack, (int)tid);
pPoolStack->release();
}
return pPoolStack;
}
CCAutoreleasePool* CCPoolManager::getCurReleasePool(bool autoCreate)
{
// if(!m_pCurReleasePool)
// {
// push();
// }
//
// CCAssert(m_pCurReleasePool, "current auto release pool should not be null");
//
// return m_pCurReleasePool;
CCAutoreleasePool* pReleasePool = NULL;
CCArray* pPoolStack = getCurReleasePoolStack();
if(pPoolStack->count() > 0)
{
pReleasePool = (CCAutoreleasePool*)pPoolStack->lastObject();
}
if (!pReleasePool && autoCreate) {
CCAutoreleasePool* pPool = new CCAutoreleasePool(); //ref = 1
pPoolStack->addObject(pPool); //ref = 2
pPool->release(); //ref = 1
pReleasePool = pPool;
}
return pReleasePool;
}
/////【diff - end】- by layne//////
代码下载地址:https://github.com/kaitiren/pthread-test-for-cocos2dx

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

對於機械硬碟、或SATA固態硬碟,軟體運轉速度的提升會有感覺,如果是NVME硬碟,可能感覺不到。一,註冊表導入桌面新建一個文字文檔,複製貼上如下內容,另存為1.reg,然後右鍵合併,並重新啟動電腦。 WindowsRegistryEditorVersion5.00[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SessionManager\MemoryManagement]"DisablePagingExecutive"=d

最近,小米發布了一款功能強大的高階智慧型手機小米14Pro,它不僅外觀設計時尚,而且擁有內在和外在的黑科技。這款手機擁有頂級的性能和出色的多工處理能力,讓用戶能夠享受快速且流暢的手機使用體驗。但效能也是會收到記憶體的影響的,很多用戶想要知道小米14Pro如何查看記憶體佔用,趕快來看看吧。小米14Pro如何查看記憶體佔用?小米14Pro查看記憶體佔用方法介紹開啟小米14Pro手機【設定】中的【應用程式管理】按鈕。查看已安裝的所有應用程式列表,瀏覽列表並找到你想查看的應用,點擊它進入應用程式詳細頁面。在應用程式詳細頁面中

當您在您的同步資料夾中發現一個或多個項目與Outlook中的錯誤訊息不符時,這可能是因為您更新或取消了會議項目。在這種情況下,您會看到一條錯誤訊息,提示您的本機資料版本與遠端副本有衝突。這種情況通常發生在Outlook桌面應用程式中。您同步的資料夾中的一個或多個項目不符。若要解決衝突,請開啟這些項目,然後重試此操作。修復同步的資料夾中的一個或多個項目不符合Outlook錯誤在Outlook桌面版中,當本機行事曆項目與伺服器副本發生衝突時,可能會遇到問題。不過,幸運的是,有一些簡單的方法可以幫助您

本站9月3日消息,韓媒etnews當地時間昨報道稱,三星電子和SK海力士的「類HBM式」堆疊結構行動記憶體產品將在2026年後實現商業化。消息人士表示這兩大韓國記憶體巨頭將堆疊式行動記憶體視為未來重要收入來源,並計劃將「類HBM記憶體」擴展到智慧型手機、平板電腦和筆記型電腦中,為端側AI提供動力。綜合本站先前報導,三星電子的此類產品叫做LPWideI/O內存,SK海力士則將這方面技術稱為VFO。兩家企業使用了大致相同的技術路線,即將扇出封裝和垂直通道結合在一起。三星電子的LPWideI/O內存位寬達512

報告稱,三星電子的高層DaeWooKim表示,在2024年韓國微電子和封裝學會年會上,三星電子將完成採用16層混合鍵結HBM記憶體技術的驗證。據悉,這項技術已通過技術驗證。報告也稱,此次技術驗證將為未來若干年內的記憶體市場發展奠定基礎。 DaeWooKim表示,三星電子成功製造了基於混合鍵合技術的16層堆疊HBM3內存,該內存樣品工作正常,未來16層堆疊混合鍵合技術將用於HBM4內存量產。 ▲圖源TheElec,下同相較現有鍵合工藝,混合鍵結無需在DRAM記憶體層間添加凸塊,而是將上下兩層直接銅對銅連接,

本站3月21日消息,美光在發布季度財報後舉行了電話會議。在該會議上美光CEO桑傑・梅赫羅特拉(SanjayMehrotra)表示,相對於傳統內存,HBM對晶圓量的消耗明顯更高。美光錶示,在同一節點生產同等容量的情況下,目前最先進的HBM3E內存對晶圓量的消耗是標準DDR5的三倍,並且預計隨著性能的提升和封裝複雜度的加劇,在未來的HBM4上這一比值將進一步提升。參考本站以往報道,這一高比值有相當一部分原因在HBM的低良率上。 HBM記憶體採用多層DRAM記憶體TSV連線堆疊而成,一層出現問題就意味著整個

本站5月6日消息,雷克沙Lexar推出Ares戰神之翼系列DDR57600CL36超頻內存,16GBx2套條5月7日0點開啟50元定金預售,至手價1299元。雷克沙戰神之翼記憶體採用海力士A-die記憶體顆粒,支援英特爾XMP3.0,提供以下兩個超頻預設:7600MT/s:CL36-46-46-961.4V8000MT/s:CL38-48-49 -1001.45V散熱方面,此內存套裝搭載1.8mm厚度的全鋁散熱馬甲,配備PMIC專屬導熱矽脂墊。記憶體採用8顆高亮LED燈珠,支援13種RGB燈光模式,可

根據TrendForce的調查報告顯示,AI浪潮對DRAM記憶體和NAND快閃記憶體市場帶來明顯影響。在本站5月7日消息中,TrendForce集邦諮詢在今日的最新研報中稱該機構調升本季兩類儲存產品的合約價格漲幅。具體而言,TrendForce原先預估2024年第二季DRAM記憶體合約上漲3~8%,現估計為13~18%;而在NAND快閃記憶體方面,原預估上漲13~18%,新預估為15 ~20%,僅eMMC/UFS漲幅較低,為10%。 ▲圖源TrendForce集邦諮詢TrendForce表示,該機構原預計在連續
