OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Ogre::ArrayMemoryManager Class Reference

Abstract memory manager for managing large chunks of contiguous memory, optimized for SoA (Structure of Arrays) implementations. More...

#include <OgreArrayMemoryManager.h>

+ Inheritance diagram for Ogre::ArrayMemoryManager:
+ Collaboration diagram for Ogre::ArrayMemoryManager:


class  RebaseListener
 When mUsedMemory >= mMaxMemory (that is, we've exhausted all our preallocated memory) ArrayMemoryManager will proceed to reallocate all memory. More...

Public Types

enum  ManagerType {
  NodeType, ObjectDataType, BoneType, UserDefinedType0,
  UserDefinedType1, UserDefinedType2, UserDefinedType3, UserDefinedType4,
  UserDefinedType5, UserDefinedType6, NumStructTypes
typedef std::vector< ptrdiff_t > PtrdiffVec

Public Member Functions

 ArrayMemoryManager (ManagerType managerType, size_t const *elementsMemSize, CleanupRoutines const *cleanupRoutines, size_t numElementsSize, uint16 depthLevel, size_t hintMaxNodes, size_t cleanupThreshold=100, size_t maxHardLimit=MAX_MEMORY_SLOTS, RebaseListener *rebaseListener=0)
 Constructor. More...
void destroy ()
 Destroys the memory ptrs. More...
size_t getAllMemory () const
 Gets all memory reserved for this manager. More...
size_t getFreeMemory () const
 Gets available memory in bytes. More...
size_t getUsedMemory () const
 Gets used memory in bytes (not including waste) More...
size_t getWastedMemory () const
 Gets wasted memory (perform a cleanup to fix) More...
void initialize ()
 Initializes mMemoryPools. More...

Static Public Attributes

static const size_t MAX_MEMORY_SLOTS

Protected Types

typedef std::vector< size_t > SlotsVec

Protected Member Functions

size_t createNewSlot ()
 Requests memory for a new slot (could be used for SceneNode, Entities, etc.) More...
void destroySlot (const char *ptrToFirstElement, uint8 index)
 Releases memory acquired through. More...
virtual void slotsRecreated (size_t prevNumSlots)
 Called when mMemoryPools changes, to give a chance derived class to initialize memory to default values. More...

Protected Attributes

SlotsVec mAvailableSlots
CleanupRoutines const * mCleanupRoutines
size_t mCleanupThreshold
size_t const * mElementsMemSizes
uint16 mLevel
 The hierarchy depth level. More...
ManagerType mManagerType
size_t mMaxHardLimit
size_t mMaxMemory
MemoryPoolVec mMemoryPools
 One per memory type. More...
size_t mTotalMemoryMultiplier
size_t mUsedMemory

Detailed Description

Abstract memory manager for managing large chunks of contiguous memory, optimized for SoA (Structure of Arrays) implementations.

This class works by requesting slots from preallocated chunks, and then releasing those slots. This implementation is most efficient when using LIFO patterns. Since Entities & SceneNodes use this manager, this means that you should create the most static ones first, and the most dynamic ones last (i.e. the ones that are going to be frequently inserted & removed from scene)
WARNING: This class requires its owner to manually call initialize() and destroy() after all instances have been destroyed. Otherwise memory leaks will happen!
Matias N. Goldberg

Definition at line 64 of file OgreArrayMemoryManager.h.

Member Typedef Documentation

typedef std::vector<ptrdiff_t> Ogre::ArrayMemoryManager::PtrdiffVec

Definition at line 87 of file OgreArrayMemoryManager.h.

typedef std::vector<size_t> Ogre::ArrayMemoryManager::SlotsVec

Definition at line 182 of file OgreArrayMemoryManager.h.

Member Enumeration Documentation


Definition at line 67 of file OgreArrayMemoryManager.h.

Constructor & Destructor Documentation

Ogre::ArrayMemoryManager::ArrayMemoryManager ( ManagerType  managerType,
size_t const *  elementsMemSize,
CleanupRoutines const *  cleanupRoutines,
size_t  numElementsSize,
uint16  depthLevel,
size_t  hintMaxNodes,
size_t  cleanupThreshold = 100,
size_t  maxHardLimit = MAX_MEMORY_SLOTS,
RebaseListener rebaseListener = 0 


intialize. destroy.

elementsMemSizeArray containing the size in bytes of each element type (i.e. NodeElementsMemSize)
cleanupRoutinesArray containing the cleanup function that will be called when performing cleanups. Many pointers can use the flatCleaner and is the fastest. However Array variables (i.e. ArrayVector3) have a layout where flatCleaner won't work correctly because the data is interleaved (rather than flat).
numElementsSizeNumber of entries in elementsMemSize
depthLevelValue only used to pass to the listener. Identifies to which hierarchy depth level this memory manager belongs to.
hintMaxNodesHint on how many SceneNodes we'll be creating.
cleanupThresholdThe threshold at which a cleanup is triggered after too many nodes have been destroyed in a non-LIFO order or without being created again. -1 to disable cleanups.
maxHardLimitMaximum amount of SceneNodes. The manager is not allowed to grow and consume more memory past that limit. MAX_MEMORY_SLOTS for no limit. This is useful when target architecture has much less memory than the dev machine.
Note that if hintMaxNodes < maxHardLimit, the manager may be forced to do temporary allocations (to do the reallocs) thus during a brief perdiod of time it may consume more memory than the established hard limit (up to 2x).
rebaseListenerThe listener to be called when cleaning up or growing the memory pool. If null, cleanupThreshold is set to -1 & maxHardLimit will be set to hintMaxNodes

Member Function Documentation

size_t Ogre::ArrayMemoryManager::createNewSlot ( )

Requests memory for a new slot (could be used for SceneNode, Entities, etc.)

Try to create everything static first, then dynamic content. Values are initialized (position to zero, orientation to identity, scale to unit, etc)
The requested slot, as an offset to the base memory pointers.
void Ogre::ArrayMemoryManager::destroy ( )

Destroys the memory ptrs.


If there were slots in use, make sure they're no longer used, as their ptrs will become dangling ptrs. We don't assert because this may be valid behavior (i.e. on shutdown)
void Ogre::ArrayMemoryManager::destroySlot ( const char *  ptrToFirstElement,
uint8  index 

Releases memory acquired through.

See also
For optimal results, try to respect LIFO order in the removals
ptrToFirstElementPointer to the first element, what's allocated with mMemoryPools[0]
indexThe index, typically mIndex (range [0; ARRAY_PACKED_REALS) )
size_t Ogre::ArrayMemoryManager::getAllMemory ( ) const

Gets all memory reserved for this manager.

size_t Ogre::ArrayMemoryManager::getFreeMemory ( ) const

Gets available memory in bytes.

size_t Ogre::ArrayMemoryManager::getUsedMemory ( ) const

Gets used memory in bytes (not including waste)

size_t Ogre::ArrayMemoryManager::getWastedMemory ( ) const

Gets wasted memory (perform a cleanup to fix)

void Ogre::ArrayMemoryManager::initialize ( )

Initializes mMemoryPools.

Once it has been called, destroy() must be called. destroy

The destructor won't free the data, if you don't call destroy, memory will leak. Calling initialize twice is possible and won't leak, but will free the previous memory ptrs without calling the registered RebaseListener. So if there were slots in use, their pointers will become dangling. An assert will trigger if this happens.
virtual void Ogre::ArrayMemoryManager::slotsRecreated ( size_t  prevNumSlots)

Called when mMemoryPools changes, to give a chance derived class to initialize memory to default values.

prevNumSlotsThe previous value of mMaxMemory before changing mMemoryPools

Reimplemented in Ogre::ObjectDataArrayMemoryManager, Ogre::NodeArrayMemoryManager, and Ogre::BoneArrayMemoryManager.

Definition at line 285 of file OgreArrayMemoryManager.h.

Member Data Documentation

SlotsVec Ogre::ArrayMemoryManager::mAvailableSlots

Definition at line 183 of file OgreArrayMemoryManager.h.

const size_t Ogre::ArrayMemoryManager::MAX_MEMORY_SLOTS

Definition at line 194 of file OgreArrayMemoryManager.h.

CleanupRoutines const* Ogre::ArrayMemoryManager::mCleanupRoutines

Definition at line 174 of file OgreArrayMemoryManager.h.

size_t Ogre::ArrayMemoryManager::mCleanupThreshold

Definition at line 181 of file OgreArrayMemoryManager.h.

size_t const* Ogre::ArrayMemoryManager::mElementsMemSizes

Definition at line 173 of file OgreArrayMemoryManager.h.

uint16 Ogre::ArrayMemoryManager::mLevel

The hierarchy depth level.

This value is not used by the manager, just passed to the listeners so they can know to which level it belongs

Definition at line 189 of file OgreArrayMemoryManager.h.

ManagerType Ogre::ArrayMemoryManager::mManagerType

Definition at line 191 of file OgreArrayMemoryManager.h.

size_t Ogre::ArrayMemoryManager::mMaxHardLimit

Definition at line 180 of file OgreArrayMemoryManager.h.

size_t Ogre::ArrayMemoryManager::mMaxMemory

Definition at line 179 of file OgreArrayMemoryManager.h.

MemoryPoolVec Ogre::ArrayMemoryManager::mMemoryPools

One per memory type.

Definition at line 172 of file OgreArrayMemoryManager.h.

RebaseListener* Ogre::ArrayMemoryManager::mRebaseListener

Definition at line 184 of file OgreArrayMemoryManager.h.

size_t Ogre::ArrayMemoryManager::mTotalMemoryMultiplier

Definition at line 175 of file OgreArrayMemoryManager.h.

size_t Ogre::ArrayMemoryManager::mUsedMemory

Definition at line 178 of file OgreArrayMemoryManager.h.

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