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//////

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++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桌面版中,当本地日历项与服务器副本发生冲突时,可能会遇到问题。不过,幸运的是,有一些简单的方法可以帮助您

报道称,三星电子的高管DaeWooKim表示,在2024年韩国微电子和封装学会年会上,三星电子将完成采用16层混合键合HBM内存技术的验证。据悉,这项技术已通过技术验证。报道还称,此次技术验证将为未来若干年内的内存市场发展奠定基础。DaeWooKim表示,三星电子成功制造了基于混合键合技术的16层堆叠HBM3内存,该内存样品工作正常,未来16层堆叠混合键合技术将用于HBM4内存量产。▲图源TheElec,下同相较现有键合工艺,混合键合无需在DRAM内存层间添加凸块,而是将上下两层直接铜对铜连接,

本站9月3日消息,韩媒etnews当地时间昨日报道称,三星电子和SK海力士的“类HBM式”堆叠结构移动内存产品将在2026年后实现商业化。消息人士表示这两大韩国内存巨头将堆叠式移动内存视为未来重要收入来源,计划将“类HBM内存”扩展到智能手机、平板电脑和笔记本电脑中,为端侧AI提供动力。综合本站此前报道,三星电子的此类产品叫做LPWideI/O内存,SK海力士则将这方面技术称为VFO。两家企业使用了大致相同的技术路线,即将扇出封装和垂直通道结合在一起。三星电子的LPWideI/O内存位宽达512

本站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灯光模式,可

本站6月7日消息,金邦(GEIL)在2024台北国际电脑展上推出了其最新DDR5解决方案,而且给出了SO-DIMM、CUDIMM、CSODIMM、CAMM2和LPCAMM2等版本可选。▲图源:Wccftech如图所示,金邦展出的CAMM2/LPCAMM2内存采用非常紧凑的设计,最高可提供128GB的容量,速度最高可达8533MT/s,其中部分产品甚至可以在AMDAM5平台上稳定超频至9000MT/s,且无需任何辅助散热。据介绍,金邦2024款PolarisRGBDDR5系列内存最高可提供8400
