OGRE-Next: Ogre::ObjectMemoryManager Class Reference

| OGRE-Next 3.0.0 Object-Oriented Graphics Rendering Engine

Loading...
Searching...
No Matches
Ogre::ObjectMemoryManager Class Referencefinal
Core » Memory

Wrap-around class that contains multiple ArrayMemoryManager, one per render queue. More...

`#include <OgreObjectMemoryManager.h>`

Inheritance diagram for Ogre::ObjectMemoryManager:
[legend]

## Public Member Functions
| ObjectMemoryManager ()
virtual | ~ObjectMemoryManager ()
SceneNode * | _getDummyNode () const
| Returns the pointer to the dummy node (useful when detaching).
size_t | _getTotalRenderQueues () const
void | _setTwin (SceneMemoryMgrTypes memoryManagerType, ObjectMemoryManager *twinMemoryManager)
void | applyRebase (uint16 level, const MemoryPoolVec &newBasePtrs, const ArrayMemoryManager::PtrdiffVec &diffsList) override
| Called when the manager already grew it's memory pool to honour more node requests.
void | buildDiffList (uint16 level, const MemoryPoolVec &basePtrs, ArrayMemoryManager::PtrdiffVec &outDiffsList) override
| Called when the manager needs to grow it's memory pool to honour more node requests.
size_t | calculateTotalNumObjectDataIncludingFragmentedSlots () const
| This is the opposite of getTotalNumObjects.
void | defragment ()
| Triggers on demand a defragmentation of the pools, so that all slots become contiguous in memory.
size_t | getFirstObjectData (ObjectData &outObjectData, size_t renderQueue)
| Retrieves a ObjectData pointing to the first MovableObject in the given render queue.
SceneMemoryMgrTypes | getMemoryManagerType () const
size_t | getNumRenderQueues () const
| Retrieves the number of render queues that have been created.
size_t | getTotalNumObjects () const
| Retrieves the sum of the number of objects in all render queues.
ObjectMemoryManager * | getTwin () const
| Note the return value can be null.
void | migrateTo (ObjectData &inOutTransform, size_t renderQueue, ObjectMemoryManager *dstObjectMemoryManager)
| Releases memory belonging to us, not before copying it into another manager.
void | objectCreated (ObjectData &outObjectData, size_t renderQueue)
| Requests memory for the given ObjectData, initializing values.
void | objectDestroyed (ObjectData &outObjectData, size_t renderQueue)
| Releases current memory.
void | objectMoved (ObjectData &inOutObjectData, size_t oldRenderQueue, size_t newRenderQueue)
| Requests memory for the given ObjectData to be moved to a different render queue, transferring existing values inside to the new memory slot.
void | performCleanup (uint16 level, const MemoryPoolVec &basePtrs, size_t const *elementsMemSizes, size_t startInstance, size_t diffInstances) override
| Called when too many nodes were destroyed in a non-LIFO fashion.
void | shrinkToFit ()
| Defragments memory, then reallocates a smaller pool that tightly fits the current number of objects.

## Detailed Description

Wrap-around class that contains multiple ArrayMemoryManager, one per render queue.

Remarks
  This is the main memory manager that actually manages MovableObjects, and has to be called when a new MovableObject was created and when a MovableObject changes RenderQueue.

  Note that some SceneManager implementations (i.e. Octree like) may want to have more than one ObjectMemoryManager, for example one per octant.

## Constructor & Destructor Documentation

## ◆ ObjectMemoryManager()

Ogre::ObjectMemoryManager::ObjectMemoryManager | ( |  | ) |

Referenced by _setTwin(), getTwin(), and migrateTo().

## ◆ ~ObjectMemoryManager()

virtual Ogre::ObjectMemoryManager::~ObjectMemoryManager | ( |  | ) |
| virtual

## Member Function Documentation

## ◆ _getDummyNode()

SceneNode * Ogre::ObjectMemoryManager::_getDummyNode | ( |  | ) | const
| inline

Returns the pointer to the dummy node (useful when detaching).

## ◆ _getTotalRenderQueues()

size_t Ogre::ObjectMemoryManager::_getTotalRenderQueues | ( |  | ) | const
| inline

## ◆ _setTwin()

void Ogre::ObjectMemoryManager::_setTwin | ( | SceneMemoryMgrTypes | memoryManagerType,
|  | ObjectMemoryManager * | twinMemoryManager )

See also
  mMemoryManagerType

References ObjectMemoryManager().

## ◆ applyRebase()

void Ogre::ObjectMemoryManager::applyRebase | ( | uint16 | level,
|  | const MemoryPoolVec & | newBasePtrs,
|  | const ArrayMemoryManager::PtrdiffVec & | diffsList )
| overridevirtual

Called when the manager already grew it's memory pool to honour more node requests.

Remarks
  Will use the new base ptr and the list we built in

See also
  buildDiffList() to know what mChunkPtr & mIndex needs to be set for each ArrayVector3/etc we have.

Parameters

  level | The hierarchy depth level
  newBasePtrs | The new base ptr.
  diffsList | The list built in buildDiffList

Implements Ogre::ArrayMemoryManager::RebaseListener.

## ◆ buildDiffList()

void Ogre::ObjectMemoryManager::buildDiffList | ( | uint16 | level,
|  | const MemoryPoolVec & | basePtrs,
|  | ArrayMemoryManager::PtrdiffVec & | outDiffsList )
| overridevirtual

Called when the manager needs to grow it's memory pool to honour more node requests.

See the class description on why we need to do this (to avoid C++ undefined behavior)

Remarks
  Needs to builds a list that will contain the difference in bytes between each ArrayVector3/ArrayMatrix4/etc and the base pointers in_the_order in which the derived class holds those pointers (i.e. in the order the SceneNodes are arranged in memory)

Parameters

  level | The hierarchy depth level
  basePtrs | The base pointers from each pool so we can calculate the differences
  outDiffsList | The list we'll generate. "outDiffsList" already has enough reserved space

Implements Ogre::ArrayMemoryManager::RebaseListener.

## ◆ calculateTotalNumObjectDataIncludingFragmentedSlots()

size_t Ogre::ObjectMemoryManager::calculateTotalNumObjectDataIncludingFragmentedSlots | ( |  | ) | const

This is the opposite of getTotalNumObjects.

This function returns the sum of the return values of getFirstObjectData

## ◆ defragment()

void Ogre::ObjectMemoryManager::defragment | ( |  | ) |

Triggers on demand a defragmentation of the pools, so that all slots become contiguous in memory.

ArrayMemoryManager::destroySlot already does this when the number of fragmented slots reaches mCleanupThreshold

## ◆ getFirstObjectData()

size_t Ogre::ObjectMemoryManager::getFirstObjectData | ( | ObjectData & | outObjectData,
|  | size_t | renderQueue )

Retrieves a ObjectData pointing to the first MovableObject in the given render queue.

Parameters

  outObjectData | [out] ObjectData with filled pointers to the first MovableObject in this depth
  renderQueue | Current render queue it belongs to.

Returns
  Number of MovableObject in this depth level

## ◆ getMemoryManagerType()

SceneMemoryMgrTypes Ogre::ObjectMemoryManager::getMemoryManagerType | ( |  | ) | const
| inline

## ◆ getNumRenderQueues()

size_t Ogre::ObjectMemoryManager::getNumRenderQueues | ( |  | ) | const

Retrieves the number of render queues that have been created.

Remarks
  The return value is equal or below mMemoryManagers.size(), you should cache the result instead of calling this function too often.

## ◆ getTotalNumObjects()

size_t Ogre::ObjectMemoryManager::getTotalNumObjects | ( |  | ) | const
| inline

Retrieves the sum of the number of objects in all render queues.

Remarks
  The value is cached to avoid iterating through all RQ levels, however be VERY CAREFUL with this value it may not be equal to the sum of all getFirstObjectData() from all render queues. Specially careful when distributing work to different threads, since you may have to include skipping unassigned slots, and thus the last thread may end up writing out of bounds if you use getTotalNumObjects to allocate a buffer to hold results instead of calculateTotalNumObjectDataIncludingFragmentedSlots (depends on how your algorithm works).

  When ARRAY_PACKED_REALS = 4, and 4 objects have been created but the 2nd one has been deleted, getFirstObjectData will still return 4 until the 4th object is removed or a cleanup is performed; whereas getTotalNumObjects will return the actual number of objects.

## ◆ getTwin()

ObjectMemoryManager * Ogre::ObjectMemoryManager::getTwin | ( |  | ) | const
| inline

Note the return value can be null.

References ObjectMemoryManager().

## ◆ migrateTo()

void Ogre::ObjectMemoryManager::migrateTo | ( | ObjectData & | inOutTransform,
|  | size_t | renderQueue,
|  | ObjectMemoryManager * | dstObjectMemoryManager )

Releases memory belonging to us, not before copying it into another manager.

Remarks
  This function is useful when implementing multiple Memory Managers in Scene Managers or when switching nodes from Static to/from Dynamic.

Parameters

  inOutTransform | Valid Transform that belongs to us. Output will belong to the other memory mgr.
  depth | Current hierarchy level depth it belongs to.
  dstObjectMemoryManager | ObjectMemoryManager that will now own the transform.

References ObjectMemoryManager().

## ◆ objectCreated()

void Ogre::ObjectMemoryManager::objectCreated | ( | ObjectData & | outObjectData,
|  | size_t | renderQueue )

Requests memory for the given ObjectData, initializing values.

Parameters

  outObjectData | ObjectData with filled pointers
  renderQueue | RenderQueue ID.

## ◆ objectDestroyed()

void Ogre::ObjectMemoryManager::objectDestroyed | ( | ObjectData & | outObjectData,
|  | size_t | renderQueue )

Releases current memory.

Parameters

  outObjectData | ObjectData whose pointers will be nullified.
  renderQueue | Current render queue it belongs to.

## ◆ objectMoved()

void Ogre::ObjectMemoryManager::objectMoved | ( | ObjectData & | inOutObjectData,
|  | size_t | oldRenderQueue,
|  | size_t | newRenderQueue )

Requests memory for the given ObjectData to be moved to a different render queue, transferring existing values inside to the new memory slot.

Parameters

  inOutObjectData | ObjectData with filled pointers
  oldRenderQueue | RenderQueue it's living now.
  newRenderQueue | RenderQueue it wants to live in.

## ◆ performCleanup()

void Ogre::ObjectMemoryManager::performCleanup | ( | uint16 | level,
|  | const MemoryPoolVec & | basePtrs,
|  | size_t const * | elementsMemSizes,
|  | size_t | startInstance,
|  | size_t | diffInstances )
| overridevirtual

Called when too many nodes were destroyed in a non-LIFO fashion.

Without cleaning up, the scene manager will waste CPU & bandwidth on processing vectors & matrices that are not in use. The more fragmented/unordered those removals were, the worst it is. Try to create everything static first, then dynamic content.

Remarks
  The manager behaves similarly to a Garbage Collector, as it is triggered after certain amount of nodes have been freed (unless they respected LIFO order)

In a way, it's very similar to vector::remove(), as removing an element from the middle means we need to shift everything past that point one place (or more).

Parameters

  level | The hierarchy depth level
  basePtrs | The base ptrs.
  startInstance | The instance to which past that we need to shift
  diffInstances | How many places we need to shift backwards.

Implements Ogre::ArrayMemoryManager::RebaseListener.

## ◆ shrinkToFit()

void Ogre::ObjectMemoryManager::shrinkToFit | ( |  | ) |

Defragments memory, then reallocates a smaller pool that tightly fits the current number of objects.

Useful when you know you won't be creating more slots and you need to reclaim memory.

The documentation for this class was generated from the following file:

- OgreObjectMemoryManager.h