Any way to avoid defragment delay?

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
jwwalker
Goblin
Posts: 224
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 17
Contact:

Any way to avoid defragment delay?

Post by jwwalker »

In some cases, my app takes a ridiculous amount of time to quit, with the time being spent in ArrayMemoryManager::defragment as nodes are destroyed. Obviously, if I'm quitting, I don't care how fragmented memory is, so how can I avoid this?

jwwalker
Goblin
Posts: 224
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 17
Contact:

Re: Any way to avoid defragment delay?

Post by jwwalker »

In my own fork of Ogre, I came up with a workaround. I added 2 new methods,

Code: Select all

    void ArrayMemoryManager::neverDefragment()
    {
        mCleanupThreshold = std::numeric_limits<size_t>::max();
    }

and

Code: Select all

    void NodeMemoryManager::neverDefragment()
    {
        ArrayMemoryManagerVec::iterator itor = mMemoryManagers.begin();
        ArrayMemoryManagerVec::iterator endt = mMemoryManagers.end();

        while( itor != endt )
        {
            itor->neverDefragment();
            ++itor;
        }
    }

and in SceneManager::~SceneManager, I added

Code: Select all

        for( size_t i = 0; i < NUM_SCENE_MEMORY_MANAGER_TYPES; ++i )
        {
            mNodeMemoryManager[i].neverDefragment();
        }

just before the clearScene call. Seem to do the trick.

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Any way to avoid defragment delay?

Post by dark_sylinc »

  1. I've been waiting for years for someone to come up asking about this! It seems no one was bothered, or noticed?

  2. Could you submit a PR? This is definitely welcomed.

jwwalker
Goblin
Posts: 224
Joined: Thu Aug 12, 2021 10:06 pm
Location: San Diego, CA, USA
x 17
Contact:

Re: Any way to avoid defragment delay?

Post by jwwalker »

You got it, PR #281.

Post Reply