首页 > 编程知识 正文

c语言指针遍历字符串,python遍历嵌套字典

时间:2023-05-03 14:29:15 阅读:36872 作者:4334

I ' veinheritedasubstantialqt 5项目,wheretheaccumulativememoryleakageisbecomingaseriousissue.(memoryleakageshouldrarelyysue )

thisguireadsimagedataintoobjectsofavoxelclass,tobedisplayedgraphically.thedatacomeseitherfromfileorbuffer (

when an image is自读取文件,cvoxelisinitializedusingqvector.resize (0)。

When an image save to file is opened,alocalvoxelpointeriscreatedandpushedtotheendofcvoxel,onceforeverypixelsoloopingoverallllrowsansansatind

for(irow=0; iRow nRows; iRow )

{

for(icol=0; iCol nCols; iCol )

{

Voxel *v=new Voxel;

//codeforreadingdataintocvoxelremovedhere

.

}

}

courtesyoftheusefulcommentsbelow,I ' venowhadsomesuccessinseeingmemoryusagedecreaseinthewindowstaskmanager,bynestingdestestrurur

for(irow=0; iRow nRows; iRow )

{

for(icol=0; iCol nCols; iCol )

{

delete cVoxel[iRow][iCol];

}

}

Ideally,amajorrewriteisthebestsolution.butintherealworld,I ' llhavetotryandfixthebiggerleaksandhopethat ' senoughuntilthat

I ' velookedatmemoryleakagesinvoxelitself,but there's nothing obvious there。

myresearchrevealsthatlookingatthewindowstaskmanagerformemoryconsumptionisn ' tentirelyreliable (win7isn ' tareal-timeos ) . butifopeningafileincreasestheapplicationmemoryconsumptionfrom 16 MTO 81.5 m, thensurelythereshouldbesomememorydecreaseiftheallocacation if I keep opening and shut images,the app ' smemoryconsumptionkeepsincreation

Right now,there ' snoattempttoreleaseanymemoryassigned (usingthenewoperator ) TOC voxel.ihavetriedafewapproaches (andreadtted

--- -编辑--- -

apologiesforthemessyad-hodcommentingbelow,butthisiscertainlyhelpingmereducethememoryleakages (completestoppagewillhopefuleages

I ' veeditedin-lineaboveto (hopefully ) make this post clearer,andremovedmybestcaseeffortasithadnoimpactonthememoryleak.thh

ialsoneedtoinvestigate @ Richard citter (sp? ) polymorphism关联的suggestion。

--- EDIT3 ---

Removed Edit2,postedthat(new ) question separately here。

Also,I ' mprettyconfidenttheanswerbelowshouldfixthisquestion-ijustneedtofigureouthowtouseqvector.resize (

解决方案

@ someprogrammerdude : you got me9/10 towardsthesolution.id on ' tknowwhetherishouldedityouranswerorusethis,so moderator(s ()

As outlined in a connected SO post,idecidedagainstsmartpointersintheend.theabovesolutionintroduced (格式) )。 theissueofthecompilertryingtoreferenceadeletedfunction.otherwiseitiscorrectwithacoupleofmodifications 3360

Initialisation:

内存评估:

{

for(intI=0; i rows; I )

{

for(intj=0; 日寇; j )

{

Voxel *v=new Voxel;

}

}

}

finallydtorreleasingthememory :

int iRow,iCol;

for(irow=0; iRow rows; iRow )

{

for(icol=0; ICOL; iCol )

{

delete cVoxel[iRow][iCol];

}

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。