OGRE 2.1
Object-Oriented Graphics Rendering Engine
Loading...
Searching...
No Matches
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:

Classes

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

Public Types

typedef std::vector< ptrdiff_tPtrdiffVec
 

Public Member Functions

 ArrayMemoryManager (size_t const *elementsMemSize, CleanupRoutines const *initRoutines, 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.
 
void destroy ()
 Destroys the memory ptrs.
 
size_t getAllMemory () const
 Gets all memory reserved for this manager.
 
size_t getFreeMemory () const
 Gets available memory in bytes.
 
size_t getNumUsedSlotsIncludingFragmented () const
 Returns mUsedMemory.
 
size_t getUsedMemory () const
 Gets used memory in bytes (not including waste)
 
size_t getWastedMemory () const
 Gets wasted memory (perform a cleanup to fix)
 
void initialize ()
 Initializes mMemoryPools.
 

Static Public Attributes

static const size_t MAX_MEMORY_SLOTS
 

Detailed Description

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

Remarks
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!
Author
Matias N. Goldberg
Version
1.0

Member Typedef Documentation

◆ PtrdiffVec

Constructor & Destructor Documentation

◆ ArrayMemoryManager()

Ogre::ArrayMemoryManager::ArrayMemoryManager ( size_t const elementsMemSize,
CleanupRoutines const initRoutines,
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.

@See intialize. @See destroy.

Parameters
elementsMemSizeArray containing the size in bytes of each element type (i.e. NodeElementsMemSize)
initRoutinesArray containing the cleanup function that will be called when default initializing memory. Unlike cleanupRoutines, just leave the function pointer null if all you want is just to initialize to 0.
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).
Parameters
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

◆ destroy()

void Ogre::ArrayMemoryManager::destroy ( )

Destroys the memory ptrs.

@See initialize

Remarks
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)

◆ getAllMemory()

size_t Ogre::ArrayMemoryManager::getAllMemory ( ) const

Gets all memory reserved for this manager.

◆ getFreeMemory()

size_t Ogre::ArrayMemoryManager::getFreeMemory ( ) const

Gets available memory in bytes.

◆ getNumUsedSlotsIncludingFragmented()

size_t Ogre::ArrayMemoryManager::getNumUsedSlotsIncludingFragmented ( ) const

Returns mUsedMemory.

When ARRAY_PACKED_REALS = 4, and 4 objects have been created but the 2nd one has been deleted, getNumUsedSlotsIncludingFragmented will still return 4 until the 4th object is removed or a cleanup is performed

◆ getUsedMemory()

size_t Ogre::ArrayMemoryManager::getUsedMemory ( ) const

Gets used memory in bytes (not including waste)

◆ getWastedMemory()

size_t Ogre::ArrayMemoryManager::getWastedMemory ( ) const

Gets wasted memory (perform a cleanup to fix)

◆ initialize()

void Ogre::ArrayMemoryManager::initialize ( )

Initializes mMemoryPools.

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

Remarks
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.

Member Data Documentation

◆ MAX_MEMORY_SLOTS

const size_t Ogre::ArrayMemoryManager::MAX_MEMORY_SLOTS
static

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