OGRE  1.8
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreMemoryAllocatorConfig.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __MemoryAllocatorConfig_H__
30 #define __MemoryAllocatorConfig_H__
31 
33 
114 
119 
124 
127 
130 
140 namespace Ogre
141 {
159  {
176 
177 
178  // sentinel value, do not use
180  };
184 }
185 
187 #include "OgreMemorySTLAllocator.h"
188 
189 #if OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_NEDPOOLING
190 
191 # include "OgreMemoryNedPooling.h"
192 namespace Ogre
193 {
194  // configure default allocators based on the options above
195  // notice how we're not using the memory categories here but still roughing them out
196  // in your allocators you might choose to create different policies per category
197 
198  // configurable category, for general malloc
199  // notice how we ignore the category here, you could specialise
200  template <MemoryCategory Cat> class CategorisedAllocPolicy : public NedPoolingPolicy{};
201  template <MemoryCategory Cat, size_t align = 0> class CategorisedAlignAllocPolicy : public NedPoolingAlignedPolicy<align>{};
202 }
203 
204 #elif OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_NED
205 
206 # include "OgreMemoryNedAlloc.h"
207 namespace Ogre
208 {
209  // configure default allocators based on the options above
210  // notice how we're not using the memory categories here but still roughing them out
211  // in your allocators you might choose to create different policies per category
212 
213  // configurable category, for general malloc
214  // notice how we ignore the category here, you could specialise
215  template <MemoryCategory Cat> class CategorisedAllocPolicy : public NedAllocPolicy{};
216  template <MemoryCategory Cat, size_t align = 0> class CategorisedAlignAllocPolicy : public NedAlignedAllocPolicy<align>{};
217 }
218 
219 #elif OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_STD
220 
221 # include "OgreMemoryStdAlloc.h"
222 namespace Ogre
223 {
224  // configure default allocators based on the options above
225  // notice how we're not using the memory categories here but still roughing them out
226  // in your allocators you might choose to create different policies per category
227 
228  // configurable category, for general malloc
229  // notice how we ignore the category here
230  template <MemoryCategory Cat> class CategorisedAllocPolicy : public StdAllocPolicy{};
231  template <MemoryCategory Cat, size_t align = 0> class CategorisedAlignAllocPolicy : public StdAlignedAllocPolicy<align>{};
232 
233  // if you wanted to specialise the allocation per category, here's how it might work:
234  // template <> class CategorisedAllocPolicy<MEMCATEGORY_SCENE_OBJECTS> : public YourSceneObjectAllocPolicy{};
235  // template <size_t align> class CategorisedAlignAllocPolicy<MEMCATEGORY_SCENE_OBJECTS, align> : public YourSceneObjectAllocPolicy<align>{};
236 
237 
238 }
239 
240 #else
241 
242 // your allocators here?
243 
244 #endif
245 
246 namespace Ogre
247 {
248  // Useful shortcuts
257 
258  // Now define all the base classes for each allocation
267 
268 
269  // Per-class allocators defined here
270  // NOTE: small, non-virtual classes should not subclass an allocator
271  // the virtual function table could double their size and make them less efficient
272  // use primitive or STL allocators / deallocators for those
319 
320  // Containers (by-value only)
321  // Will be of the form:
322  // typedef STLAllocator<T, DefaultAllocPolicy, Category> TAlloc;
323  // for use in vector<T, TAlloc>::type
324 
325 
326 
327 }
328 
329 // Util functions
330 namespace Ogre
331 {
343  template<typename T>
344  T* constructN(T* basePtr, size_t count)
345  {
346  for (size_t i = 0; i < count; ++i)
347  {
348  new ((void*)(basePtr+i)) T();
349  }
350  return basePtr;
351  }
355 }
356 // define macros
357 
365 #if OGRE_DEBUG_MODE
366 
368 # define OGRE_MALLOC(bytes, category) ::Ogre::CategorisedAllocPolicy<category>::allocateBytes(bytes, __FILE__, __LINE__, __FUNCTION__)
369 # define OGRE_ALLOC_T(T, count, category) static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__))
371 # define OGRE_FREE(ptr, category) ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr)
373 
375 # define OGRE_NEW_T(T, category) new (::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T), __FILE__, __LINE__, __FUNCTION__)) T
376 # define OGRE_NEW_ARRAY_T(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__)), count)
378 # define OGRE_DELETE_T(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr);}
380 # define OGRE_DELETE_ARRAY_T(ptr, T, count, category) if(ptr){for (size_t b = 0; b < count; ++b) { (ptr)[b].~T();} ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr);}
382 
383 // aligned allocation
385 # define OGRE_MALLOC_SIMD(bytes, category) ::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(bytes, __FILE__, __LINE__, __FUNCTION__)
386 # define OGRE_MALLOC_ALIGN(bytes, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(bytes, __FILE__, __LINE__, __FUNCTION__)
388 # define OGRE_ALLOC_T_SIMD(T, count, category) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__))
390 # define OGRE_ALLOC_T_ALIGN(T, count, category, align) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__))
392 # define OGRE_FREE_SIMD(ptr, category) ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes(ptr)
394 # define OGRE_FREE_ALIGN(ptr, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes(ptr)
396 
398 # define OGRE_NEW_T_SIMD(T, category) new (::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T), __FILE__, __LINE__, __FUNCTION__)) T
399 # define OGRE_NEW_ARRAY_T_SIMD(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__)), count)
401 # define OGRE_DELETE_T_SIMD(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes(ptr);}
403 # define OGRE_DELETE_ARRAY_T_SIMD(ptr, T, count, category) if(ptr){for (size_t b = 0; b < count; ++b) { (ptr)[b].~T();} ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes(ptr);}
405 # define OGRE_NEW_T_ALIGN(T, category, align) new (::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T), __FILE__, __LINE__, __FUNCTION__)) T
407 # define OGRE_NEW_ARRAY_T_ALIGN(T, count, category, align) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__)), count)
409 # define OGRE_DELETE_T_ALIGN(ptr, T, category, align) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes(ptr);}
411 # define OGRE_DELETE_ARRAY_T_ALIGN(ptr, T, count, category, align) if(ptr){for (size_t _b = 0; _b < count; ++_b) { (ptr)[_b].~T();} ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes(ptr);}
413 
414 // new / delete for classes deriving from AllocatedObject (alignment determined by per-class policy)
415 // Also hooks up the file/line/function params
416 // Can only be used with classes that derive from AllocatedObject since customised new/delete needed
417 # define OGRE_NEW new (__FILE__, __LINE__, __FUNCTION__)
418 # define OGRE_DELETE delete
419 
420 
421 #else // !OGRE_DEBUG_MODE
422 
424 # define OGRE_MALLOC(bytes, category) ::Ogre::CategorisedAllocPolicy<category>::allocateBytes(bytes)
425 # define OGRE_ALLOC_T(T, count, category) static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count)))
427 # define OGRE_FREE(ptr, category) ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr)
429 
431 # define OGRE_NEW_T(T, category) new (::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T))) T
432 # define OGRE_NEW_ARRAY_T(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count))), count)
434 # define OGRE_DELETE_T(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr);}
436 # define OGRE_DELETE_ARRAY_T(ptr, T, count, category) if(ptr){for (size_t b = 0; b < count; ++b) { (ptr)[b].~T();} ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr);}
438 
439 // aligned allocation
441 # define OGRE_MALLOC_SIMD(bytes, category) ::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(bytes)
442 # define OGRE_MALLOC_ALIGN(bytes, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(bytes)
444 # define OGRE_ALLOC_T_SIMD(T, count, category) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T)*(count)))
446 # define OGRE_ALLOC_T_ALIGN(T, count, category, align) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T)*(count)))
448 # define OGRE_FREE_SIMD(ptr, category) ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes((void*)ptr)
450 # define OGRE_FREE_ALIGN(ptr, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes((void*)ptr)
452 
454 # define OGRE_NEW_T_SIMD(T, category) new (::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T))) T
455 # define OGRE_NEW_ARRAY_T_SIMD(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T)*(count))), count)
457 # define OGRE_DELETE_T_SIMD(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes((void*)ptr);}
459 # define OGRE_DELETE_ARRAY_T_SIMD(ptr, T, count, category) if(ptr){for (size_t b = 0; b < count; ++b) { (ptr)[b].~T();} ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes((void*)ptr);}
461 # define OGRE_NEW_T_ALIGN(T, category, align) new (::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T))) T
463 # define OGRE_NEW_ARRAY_T_ALIGN(T, count, category, align) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T)*(count))), count)
465 # define OGRE_DELETE_T_ALIGN(ptr, T, category, align) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes((void*)ptr);}
467 # define OGRE_DELETE_ARRAY_T_ALIGN(ptr, T, count, category, align) if(ptr){for (size_t _b = 0; _b < count; ++_b) { (ptr)[_b].~T();} ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes((void*)ptr);}
469 
470 // new / delete for classes deriving from AllocatedObject (alignment determined by per-class policy)
471 # define OGRE_NEW new
472 # define OGRE_DELETE delete
473 
474 #endif // OGRE_DEBUG_MODE
475 
476 
477 namespace Ogre
478 {
483  template<typename T>
484  void deletePtr(T* ptr)
485  {
486  OGRE_DELETE ptr;
487  }
488 }
489 
493 #endif
GeneralAllocatedObject DynLibAlloc
ScriptingAllocatedObject AbstractNodeAlloc
ScriptingAllocatedObject ScriptTranslatorAlloc
GeneralAllocatedObject LogAlloc
SceneCtlAllocatedObject ShadowDataAlloc
ResourceAllocatedObject ResourceAlloc
AnimationAllocatedObject AnimableAlloc
GeneralAllocatedObject UtilityAlloc
CategorisedAllocPolicy< Ogre::MEMCATEGORY_GEOMETRY > GeometryAllocPolicy
GeometryAllocatedObject ProgMeshAlloc
AllocatedObject< SceneObjAllocPolicy > SceneObjAllocatedObject
RenderSysAllocatedObject ViewportAlloc
CategorisedAllocPolicy< Ogre::MEMCATEGORY_SCENE_OBJECTS > SceneObjAllocPolicy
Animation data like tracks, bone matrices.
AllocatedObject< AnimationAllocPolicy > AnimationAllocatedObject
SceneObjAllocatedObject SubEntityAlloc
SceneCtlAllocatedObject LodAlloc
ResourceAllocatedObject TechniqueAlloc
ResourceAllocatedObject CompositorInstAlloc
SceneObjAllocatedObject OverlayAlloc
GeneralAllocatedObject PluginAlloc
GeneralAllocatedObject ConfigAlloc
ResourceAllocatedObject TextureUnitStateAlloc
RenderSysAllocatedObject RenderSysAlloc
GeneralAllocatedObject ProfilerAlloc
ResourceAllocatedObject PassAlloc
MemoryCategory
A set of categories that indicate the purpose of a chunk of memory being allocated.
RenderSysAllocatedObject GpuParamsAlloc
GeneralAllocatedObject CodecAlloc
GeometryAllocatedObject BatchedGeometryAlloc
CategorisedAllocPolicy< Ogre::MEMCATEGORY_GENERAL > GeneralAllocPolicy
CategorisedAllocPolicy< Ogre::MEMCATEGORY_SCENE_CONTROL > SceneCtlAllocPolicy
CategorisedAllocPolicy< Ogre::MEMCATEGORY_RESOURCE > ResourceAllocPolicy
SceneObjAllocatedObject MovableAlloc
An allocation policy for use with AllocatedObject and STLAllocator.
T * constructN(T *basePtr, size_t count)
Utility function for constructing an array of objects with placement new, without using new[] (which ...
GeneralAllocatedObject TimerAlloc
AllocatedObject< ResourceAllocPolicy > ResourceAllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
ScriptingAllocatedObject ScriptCompilerAlloc
CategorisedAllocPolicy< Ogre::MEMCATEGORY_ANIMATION > AnimationAllocPolicy
GeneralAllocatedObject RootAlloc
GeometryAllocatedObject VertexDataAlloc
SceneCtlAllocatedObject NodeAlloc
#define OGRE_DELETE
ResourceAllocatedObject SubMeshAlloc
AllocatedObject< GeneralAllocPolicy > GeneralAllocatedObject
GeneralAllocatedObject SerializerAlloc
GeometryAllocatedObject IndexDataAlloc
GeometryAllocatedObject DebugGeomAlloc
AnimationAllocatedObject AnimationAlloc
AllocatedObject< GeometryAllocPolicy > GeometryAllocatedObject
RenderSysAllocatedObject BufferAlloc
SceneCtlAllocatedObject SceneMgtAlloc
Geometry held in main memory.
AllocatedObject< SceneCtlAllocPolicy > SceneCtlAllocatedObject
GeneralAllocatedObject StreamAlloc
GeometryAllocatedObject PatchAlloc
SceneCtlAllocatedObject RenderQueueAlloc
GeneralAllocatedObject ImageAlloc
GeometryAllocatedObject EdgeDataAlloc
An allocation policy for use with AllocatedObject and STLAllocator, which aligns memory at a given bo...
CategorisedAllocPolicy< Ogre::MEMCATEGORY_SCRIPTING > ScriptingAllocPolicy
void deletePtr(T *ptr)
Function which invokes OGRE_DELETE on a given pointer.
SceneObjAllocatedObject FXAlloc
GeneralAllocatedObject FactoryAlloc
AllocatedObject< RenderSysAllocPolicy > RenderSysAllocatedObject
AllocatedObject< ScriptingAllocPolicy > ScriptingAllocatedObject
GeneralAllocatedObject ArchiveAlloc
GeneralAllocatedObject ControllerAlloc
CategorisedAllocPolicy< Ogre::MEMCATEGORY_RENDERSYS > RenderSysAllocPolicy