OGRE-Next: OgreMemoryAllocatorConfig.h File Reference

| OGRE-Next 3.0.0 Object-Oriented Graphics Rendering Engine

Loading...
Searching...
No Matches
Namespaces | Macros | Enumerations | Functions
OgreMemoryAllocatorConfig.h File Reference
Core » Memory

This file configures Ogre's memory allocators. More...

`#include "OgreMemoryAllocatedObject.h"`
`#include "OgreHeaderPrefix.h"`
`#include "OgreMemorySTLAllocator.h"`
`#include "OgreHeaderSuffix.h"`

## Namespaces
namespace | Ogre
| bswapNN may be defined as macros in <sys/endian.h> or <sys/bswap.h>

## Macros
#define | OGRE_ALLOC_DEBUG_METADATA
#define | OGRE_ALLOC_T(T, count, category)
#define | OGRE_ALLOC_T_SIMD(T, count, category)
#define | OGRE_DELETE delete
#define | OGRE_DELETE_ARRAY_T(ptr, T, count, category)
#define | OGRE_DELETE_T(ptr, T, category)
#define | OGRE_FREE(ptr, category)
#define | OGRE_FREE_ALIGN(ptr, category, align)
| Free the memory allocated with either OGRE_MALLOC_ALIGN or OGRE_ALLOC_T_ALIGN.
#define | OGRE_FREE_SIMD(ptr, category)
| Free the memory allocated with either OGRE_MALLOC_SIMD or OGRE_ALLOC_T_SIMD.
#define | OGRE_MALLOC(bytes, category)
#define | OGRE_MALLOC_ALIGN(bytes, category, align)
| Allocate a block of raw memory aligned to user defined boundaries, and indicate the category of usage.
#define | OGRE_MALLOC_SIMD(bytes, category)
| Allocate a block of raw memory aligned to SIMD boundaries, and indicate the category of usage.
#define | OGRE_NEW new
| new / delete for classes deriving from AllocatedObject (alignment determined by per-class policy)
#define | OGRE_NEW_ARRAY_T(T, count, category)
#define | OGRE_NEW_T(T, category)
| Allocate space for one primitive type, external type or non-virtual type with constructor parameters.

## Enumerations
enum | Ogre::MemoryCategory { Ogre::MEMCATEGORY_GENERAL = 0 , Ogre::MEMCATEGORY_GEOMETRY = 1 , Ogre::MEMCATEGORY_ANIMATION = 2 , Ogre::MEMCATEGORY_SCENE_CONTROL = 3 , Ogre::MEMCATEGORY_SCENE_OBJECTS = 4 , Ogre::MEMCATEGORY_RESOURCE = 5 , Ogre::MEMCATEGORY_SCRIPTING = 6 , Ogre::MEMCATEGORY_RENDERSYS = 7 , Ogre::MEMCATEGORY_COUNT = 8 }
| A set of categories that indicate the purpose of a chunk of memory being allocated. More...

## Functions
template<typename T>
T * | Ogre::constructN (T *basePtr, size_t count)
| Utility function for constructing an array of objects with placement new, without using new[] (which allocates an undocumented amount of extra memory and so isn't appropriate for custom allocators).

## Detailed Description

This file configures Ogre's memory allocators.

You can modify this file to alter the allocation routines used for Ogre's main objects.

When customising memory allocation, all you need to do is provide one or more custom allocation policy classes. These classes need to implement:

// Allocate bytes - file/line/func information should be optional,
// will be provided when available but not everywhere (e.g. release mode, STL allocations)
static inline void* allocateBytes(size_t count, const char* file = 0, int line = 0, const char* func
= 0);
// Free bytes
static inline void deallocateBytes(void* ptr);
// Return the max number of bytes available to be allocated in a single allocation
static inline size_t getMaxAllocationSize();

Policies are then used as implementations for the wrapper classes and macros which call them. AllocatedObject for example provides the hooks to override the new and delete operators for a class and redirect the functionality to the policy. STLAllocator is a class which is provided to STL containers in order to hook up allocation of the containers members to the allocation policy.

  In addition to linking allocations to policies, this class also defines a number of macros to allow debugging information to be passed along with allocations, such as the file and line number they originate from. It's important to realise that we do not redefine the 'new' and 'delete' symbols with macros, because that's very difficult to consistently do when other libraries are also trying to do the same thing; instead we use dedicated 'OGRE_' prefixed macros. See OGRE_NEW and related items.

  The base macros you can use are listed below, in order of preference and with their conditions stated:
  - OGRE_NEW - use to allocate an object which have custom new/delete operators to handle custom allocations, usually this means it's derived from Ogre::AllocatedObject. Free the memory using OGRE_DELETE. You can in fact use the regular new/delete for these classes but you won't get any line number debugging if you do. The memory category is automatically derived for these classes; for all other allocations you have to specify it.
  - OGRE_NEW_T - use to allocate a single class / struct that does not have custom new/delete operators, either because it is non-virtual (Vector3, Quaternion), or because it is from an external library (e.g. STL). You must deallocate with OGRE_DELETE_T if you expect the destructor to be called. You may free the memory using OGRE_FREE if you are absolutely sure there is no destructor to be called. These macros ensure that constructors and destructors are called correctly even though the memory originates externally (via placement new). Also note that you have to specify the type and memory category so that the correct allocator can be derived, when both allocating and freeing.
  - OGRE_NEW_ARRAY_T - as OGRE_NEW_T except with an extra parameter to construct multiple instances in contiguous memory. Again constructors and destructors are called. Free with OGRE_DELETE_ARRAY_T.
  - OGRE_ALLOC_T - use to allocate a set of primitive types conveniently with type safety. This can also be used for classes and structs but it is imperative that you understand that neither the constructor nor the destructor will be called. Sometimes you want this because it's more efficient just to grab/free a chunk of memory without having to iterate over each element constructing / destructing. Free the memory with OGRE_FREE.
  - OGRE_MALLOC - the most raw form of allocation, just a set of bytes. Use OGRE_FREE to release.
  - _SIMD and _ALIGN variants - all of the above have variations which allow aligned memory allocations. The _SIMD versions align automatically to the SIMD requirements of your platform, the _ALIGN variants allow user-defined alignment to be specified.
  Here are some examples:
  AllocatedClass* obj = OGRE_NEW AllocatedClass();
  OGRE_DELETE obj;
  AllocatedClass* array = OGRE_NEW AllocatedClass[10];
  OGRE_DELETE [] obj;
  ExternalClass* obj = OGRE_NEW_T(ExternalClass, MEMCATEGORY_GENERAL)(constructorArgs);
  OGRE_DELETE_T(obj, ExternalClass, MEMCATEGORY_GENERAL);
  ExternalClass* obj = OGRE_NEW_ARRAY_T(ExternalClass, 10, MEMCATEGORY_GENERAL);
  OGRE_DELETE_ARRAY_T(obj, NonVirtualClass, 10, MEMCATEGORY_GENERAL);
  long* pLong = OGRE_ALLOC_T(long, 10, MEMCATEGORY_GENERAL);
  OGRE_FREE(pLong, MEMCATEGORY_GENERAL);
  long* pLong = OGRE_NEW_T(long, MEMCATEGORY_GENERAL)(0);
  OGRE_FREE(pLong, MEMCATEGORY_GENERAL);
  void* pVoid = OGRE_MALLOC(1024, MEMCATEGORY_GENERAL);
  OGRE_FREE(pVoid, MEMCATEGORY_GENERAL);
  OGRE_DELETE_T
  #define OGRE_DELETE_T(ptr, T, category)
  Definition OgreMemoryAllocatorConfig.h:329
  OGRE_MALLOC
  #define OGRE_MALLOC(bytes, category)
  Definition OgreMemoryAllocatorConfig.h:353
  OGRE_ALLOC_T
  #define OGRE_ALLOC_T(T, count, category)
  Definition OgreMemoryAllocatorConfig.h:356
  OGRE_NEW_T
  #define OGRE_NEW_T(T, category)
  Allocate space for one primitive type, external type or non-virtual type with constructor parameters.
  Definition OgreMemoryAllocatorConfig.h:326
  OGRE_NEW_ARRAY_T
  #define OGRE_NEW_ARRAY_T(T, count, category)
  Definition OgreMemoryAllocatorConfig.h:337
  OGRE_NEW
  #define OGRE_NEW
  new / delete for classes deriving from AllocatedObject (alignment determined by per-class policy)
  Definition OgreMemoryAllocatorConfig.h:368
  OGRE_DELETE_ARRAY_T
  #define OGRE_DELETE_ARRAY_T(ptr, T, count, category)
  Definition OgreMemoryAllocatorConfig.h:342
  OGRE_FREE
  #define OGRE_FREE(ptr, category)
  Definition OgreMemoryAllocatorConfig.h:359
  OGRE_DELETE
  #define OGRE_DELETE
  Definition OgreMemoryAllocatorConfig.h:370
  OGRE_ALLOC_T is also the route to go for allocating real primitive types like int & float. You free the memory using OGRE_FREE, and both variants have SIMD and custom alignment variants.

## Macro Definition Documentation

## ◆ OGRE_ALLOC_DEBUG_METADATA

#define OGRE_ALLOC_DEBUG_METADATA

## ◆ OGRE_ALLOC_T

#define OGRE_ALLOC_T | ( |  | T,
|  |  | count,
|  |  | category )

Value:
static_cast<T *>( ::Ogre::AllocPolicy::allocateBytes( sizeof( T ) * ( count ) ) )

Referenced by Ogre::v1::VertexCacheProfiler::VertexCacheProfiler(), and Ogre::AxisAlignedBox::getAllCorners().

## ◆ OGRE_ALLOC_T_SIMD

#define OGRE_ALLOC_T_SIMD | ( |  | T,
|  |  | count,
|  |  | category )

Value:
static_cast<T *>( \
::Ogre::AlignAllocPolicy<>::allocateBytes( sizeof( T ) * (count)OGRE_ALLOC_DEBUG_METADATA ) )
OGRE_ALLOC_DEBUG_METADATA
#define OGRE_ALLOC_DEBUG_METADATA
Definition OgreMemoryAllocatorConfig.h:321

## ◆ OGRE_DELETE

#define OGRE_DELETE delete

Referenced by Ogre::v1::D3D11HardwareBufferManager::~D3D11HardwareBufferManager(), Ogre::v1::DefaultHardwareBufferManager::~DefaultHardwareBufferManager(), Ogre::v1::GL3PlusDefaultHardwareBufferManager::~GL3PlusDefaultHardwareBufferManager(), Ogre::v1::GL3PlusHardwareBufferManager::~GL3PlusHardwareBufferManager(), Ogre::v1::GLES2DefaultHardwareBufferManager::~GLES2DefaultHardwareBufferManager(), Ogre::v1::GLES2HardwareBufferManager::~GLES2HardwareBufferManager(), Ogre::v1::MetalHardwareBufferManager::~MetalHardwareBufferManager(), Ogre::v1::VulkanHardwareBufferManager::~VulkanHardwareBufferManager(), Ogre::APKFileSystemArchiveFactory::destroyInstance(), Ogre::FileSystemArchiveFactory::destroyInstance(), Ogre::SimplePageContentCollectionFactory::destroyInstance(), Ogre::ZipArchiveFactory::destroyInstance(), and Ogre::Lod0Stripifier::StripLod0Vertices().

## ◆ OGRE_DELETE_ARRAY_T

#define OGRE_DELETE_ARRAY_T | ( |  | ptr,
|  |  | T,
|  |  | count,
|  |  | category )

Value:
if( ptr ) \
{ \
for( size_t b = 0; b < count; ++b ) \
{ \
( ptr )[b].~T(); \
} \
::Ogre::AllocPolicy::deallocateBytes( (void *)ptr ); \
}

## ◆ OGRE_DELETE_T

#define OGRE_DELETE_T | ( |  | ptr,
|  |  | T,
|  |  | category )

Value:
if( ptr ) \
{ \
( ptr )->~T(); \
::Ogre::AllocPolicy::deallocateBytes( (void *)ptr ); \
}

Referenced by Ogre::SPFMDeleteT::operator()(), and Ogre::Any::reset().

## ◆ OGRE_FREE

#define OGRE_FREE | ( |  | ptr,
|  |  | category )

Value:
::Ogre::AllocPolicy::deallocateBytes( (void *)ptr )

Referenced by Ogre::AxisAlignedBox::~AxisAlignedBox(), and Ogre::v1::VertexCacheProfiler::~VertexCacheProfiler().

## ◆ OGRE_FREE_ALIGN

#define OGRE_FREE_ALIGN | ( |  | ptr,
|  |  | category,
|  |  | align )

Value:
::Ogre::AlignAllocPolicy<align>::deallocateBytes( (void *)ptr )

Free the memory allocated with either OGRE_MALLOC_ALIGN or OGRE_ALLOC_T_ALIGN.

Category is required to be restated to ensure the matching policy is used

## ◆ OGRE_FREE_SIMD

#define OGRE_FREE_SIMD | ( |  | ptr,
|  |  | category )

Value:
::Ogre::AlignAllocPolicy<>::deallocateBytes( (void *)ptr )

Free the memory allocated with either OGRE_MALLOC_SIMD or OGRE_ALLOC_T_SIMD.

Category is required to be restated to ensure the matching policy is used

Referenced by Ogre::FreeOnDestructor::~FreeOnDestructor(), Ogre::ImageCodec2::ImageData2::~ImageData2(), Ogre::LightListInfo::~LightListInfo(), Ogre::RawSimdUniquePtr< T, M_CATEGORY >::~RawSimdUniquePtr(), and Ogre::RawSimdUniquePtr< T, M_CATEGORY >::operator=().

## ◆ OGRE_MALLOC

#define OGRE_MALLOC | ( |  | bytes,
|  |  | category )

Value:
::Ogre::AllocPolicy::allocateBytes( bytes OGRE_ALLOC_DEBUG_METADATA )

## ◆ OGRE_MALLOC_ALIGN

#define OGRE_MALLOC_ALIGN | ( |  | bytes,
|  |  | category,
|  |  | align )

Value:
::Ogre::AlignAllocPolicy<align>::allocateBytes( bytes OGRE_ALLOC_DEBUG_METADATA )

Allocate a block of raw memory aligned to user defined boundaries, and indicate the category of usage.

## ◆ OGRE_MALLOC_SIMD

#define OGRE_MALLOC_SIMD | ( |  | bytes,
|  |  | category )

Value:
::Ogre::AlignAllocPolicy<>::allocateBytes( bytes OGRE_ALLOC_DEBUG_METADATA )

Allocate a block of raw memory aligned to SIMD boundaries, and indicate the category of usage.

Referenced by Ogre::RawSimdUniquePtr< T, M_CATEGORY >::RawSimdUniquePtr(), and Ogre::RawSimdUniquePtr< T, M_CATEGORY >::operator=().

## ◆ OGRE_NEW

#define OGRE_NEW new

new / delete for classes deriving from AllocatedObject (alignment determined by per-class policy)

Referenced by Ogre::v1::D3D11HardwareBufferManager::D3D11HardwareBufferManager(), Ogre::v1::DefaultHardwareBufferManager::DefaultHardwareBufferManager(), Ogre::v1::GL3PlusDefaultHardwareBufferManager::GL3PlusDefaultHardwareBufferManager(), Ogre::v1::GL3PlusHardwareBufferManager::GL3PlusHardwareBufferManager(), Ogre::v1::GLES2DefaultHardwareBufferManager::GLES2DefaultHardwareBufferManager(), Ogre::v1::GLES2HardwareBufferManager::GLES2HardwareBufferManager(), Ogre::v1::MetalHardwareBufferManager::MetalHardwareBufferManager(), Ogre::v1::VulkanHardwareBufferManager::VulkanHardwareBufferManager(), Ogre::BoxEmitterFactory::createEmitter(), Ogre::CylinderEmitterFactory::createEmitter(), Ogre::EllipsoidEmitterFactory::createEmitter(), Ogre::HollowEllipsoidEmitterFactory::createEmitter(), Ogre::PointEmitterFactory::createEmitter(), Ogre::RingEmitterFactory::createEmitter(), Ogre::APKFileSystemArchiveFactory::createInstance(), Ogre::APKZipArchiveFactory::createInstance(), Ogre::EmbeddedZipArchiveFactory::createInstance(), Ogre::FileSystemArchiveFactory::createInstance(), Ogre::SimplePageContentCollectionFactory::createInstance(), Ogre::ZipArchiveFactory::createInstance(), Ogre::v1::BorderPanelOverlayElementFactory::createOverlayElement(), Ogre::v1::PanelOverlayElementFactory::createOverlayElement(), and Ogre::v1::TextAreaOverlayElementFactory::createOverlayElement().

## ◆ OGRE_NEW_ARRAY_T

#define OGRE_NEW_ARRAY_T | ( |  | T,
|  |  | count,
|  |  | category )

Value:
::Ogre::constructN( static_cast<T *>( ::Ogre::AllocPolicy::allocateBytes( \
sizeof( T ) * (count)OGRE_ALLOC_DEBUG_METADATA ) ), \
count )
Ogre::constructN
T * constructN(T *basePtr, size_t count)
Utility function for constructing an array of objects with placement new, without using new[] (which ...
Definition OgreMemoryAllocatorConfig.h:305

## ◆ OGRE_NEW_T

#define OGRE_NEW_T | ( |  | T,
|  |  | category )

Value:
new( ::Ogre::AllocPolicy::allocateBytes( sizeof( T ) OGRE_ALLOC_DEBUG_METADATA ) ) T

Allocate space for one primitive type, external type or non-virtual type with constructor parameters.

Referenced by Ogre::Any::Any(), and Ogre::AnyNumeric::AnyNumeric().