Reduce memory fragmentation in COctreeTriangleSelector.

Thx@  Squarefox for reporting (http://irrlicht.sourceforge.net/forum/viewtopic.php?f=7&t=52484)
Basically the loop was split into 2 loops so children do their allocations after the parent node
has finished his. Otherwise we got fragmentation by chaotic allocation order where parents/childs
switched all the time.
Also indention of loop changed (sorry, should have done that before).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5812 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2019-05-26 15:45:19 +00:00
parent 278f5f14e4
commit 574357cb28
1 changed files with 37 additions and 28 deletions

View File

@ -96,6 +96,7 @@ void COctreeTriangleSelector::constructOctree(SOctreeNode* node)
// calculate children
if (!node->Box.isEmpty() && (s32)node->Triangles.size() > MinimalPolysPerNode)
{
for (s32 ch=0; ch<8; ++ch)
{
box.reset(middle);
@ -120,7 +121,14 @@ void COctreeTriangleSelector::constructOctree(SOctreeNode* node)
node->Triangles.set_used(keepTriangles.size());
keepTriangles.set_used(0);
}
// Note: We use an extra loop to construct child-nodes instead of doing
// that in above loop to avoid memory fragmentation which happens if
// the code has to switch between allocating memory for this node and
// the child nodes (thanks @Squarefox for noting this).
for (s32 ch=0; ch<8; ++ch)
{
if (node->Child[ch]->Triangles.empty())
{
delete node->Child[ch];
@ -129,6 +137,7 @@ void COctreeTriangleSelector::constructOctree(SOctreeNode* node)
else
constructOctree(node->Child[ch]);
}
}
}