00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright (c) 2000-2013 Torus Knot Software Ltd 00008 00009 Permission is hereby granted, free of charge, to any person obtaining a copy 00010 of this software and associated documentation files (the "Software"), to deal 00011 in the Software without restriction, including without limitation the rights 00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 00013 copies of the Software, and to permit persons to whom the Software is 00014 furnished to do so, subject to the following conditions: 00015 00016 The above copyright notice and this permission notice shall be included in 00017 all copies or substantial portions of the Software. 00018 00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 00025 THE SOFTWARE. 00026 ----------------------------------------------------------------------------- 00027 */ 00028 00029 #ifndef __MemoryAllocatorConfig_H__ 00030 #define __MemoryAllocatorConfig_H__ 00031 00032 #include "OgreMemoryAllocatedObject.h" 00033 #include "OgreHeaderPrefix.h" 00034 00115 00120 00125 00128 00131 00141 namespace Ogre 00142 { 00159 enum MemoryCategory 00160 { 00162 MEMCATEGORY_GENERAL = 0, 00164 MEMCATEGORY_GEOMETRY = 1, 00166 MEMCATEGORY_ANIMATION = 2, 00168 MEMCATEGORY_SCENE_CONTROL = 3, 00170 MEMCATEGORY_SCENE_OBJECTS = 4, 00172 MEMCATEGORY_RESOURCE = 5, 00174 MEMCATEGORY_SCRIPTING = 6, 00176 MEMCATEGORY_RENDERSYS = 7, 00177 00178 00179 // sentinel value, do not use 00180 MEMCATEGORY_COUNT = 8 00181 }; 00185 } 00186 00187 #include "OgreMemoryAllocatedObject.h" 00188 #include "OgreMemorySTLAllocator.h" 00189 00190 #if OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_NEDPOOLING 00191 00192 # include "OgreMemoryNedPooling.h" 00193 namespace Ogre 00194 { 00195 // configure default allocators based on the options above 00196 // notice how we're not using the memory categories here but still roughing them out 00197 // in your allocators you might choose to create different policies per category 00198 00199 // configurable category, for general malloc 00200 // notice how we ignore the category here, you could specialise 00201 template <MemoryCategory Cat> class CategorisedAllocPolicy : public NedPoolingPolicy{}; 00202 template <MemoryCategory Cat, size_t align = 0> class CategorisedAlignAllocPolicy : public NedPoolingAlignedPolicy<align>{}; 00203 } 00204 00205 #elif OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_NED 00206 00207 # include "OgreMemoryNedAlloc.h" 00208 namespace Ogre 00209 { 00210 // configure default allocators based on the options above 00211 // notice how we're not using the memory categories here but still roughing them out 00212 // in your allocators you might choose to create different policies per category 00213 00214 // configurable category, for general malloc 00215 // notice how we ignore the category here, you could specialise 00216 template <MemoryCategory Cat> class CategorisedAllocPolicy : public NedAllocPolicy{}; 00217 template <MemoryCategory Cat, size_t align = 0> class CategorisedAlignAllocPolicy : public NedAlignedAllocPolicy<align>{}; 00218 } 00219 00220 #elif OGRE_MEMORY_ALLOCATOR == OGRE_MEMORY_ALLOCATOR_STD 00221 00222 # include "OgreMemoryStdAlloc.h" 00223 namespace Ogre 00224 { 00225 // configure default allocators based on the options above 00226 // notice how we're not using the memory categories here but still roughing them out 00227 // in your allocators you might choose to create different policies per category 00228 00229 // configurable category, for general malloc 00230 // notice how we ignore the category here 00231 template <MemoryCategory Cat> class CategorisedAllocPolicy : public StdAllocPolicy{}; 00232 template <MemoryCategory Cat, size_t align = 0> class CategorisedAlignAllocPolicy : public StdAlignedAllocPolicy<align>{}; 00233 00234 // if you wanted to specialise the allocation per category, here's how it might work: 00235 // template <> class CategorisedAllocPolicy<MEMCATEGORY_SCENE_OBJECTS> : public YourSceneObjectAllocPolicy{}; 00236 // template <size_t align> class CategorisedAlignAllocPolicy<MEMCATEGORY_SCENE_OBJECTS, align> : public YourSceneObjectAllocPolicy<align>{}; 00237 00238 00239 } 00240 00241 #else 00242 00243 // your allocators here? 00244 00245 #endif 00246 00247 namespace Ogre 00248 { 00249 // Useful shortcuts 00250 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_GENERAL> GeneralAllocPolicy; 00251 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_GEOMETRY> GeometryAllocPolicy; 00252 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_ANIMATION> AnimationAllocPolicy; 00253 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_SCENE_CONTROL> SceneCtlAllocPolicy; 00254 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_SCENE_OBJECTS> SceneObjAllocPolicy; 00255 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_RESOURCE> ResourceAllocPolicy; 00256 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_SCRIPTING> ScriptingAllocPolicy; 00257 typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_RENDERSYS> RenderSysAllocPolicy; 00258 00259 // Now define all the base classes for each allocation 00260 typedef AllocatedObject<GeneralAllocPolicy> GeneralAllocatedObject; 00261 typedef AllocatedObject<GeometryAllocPolicy> GeometryAllocatedObject; 00262 typedef AllocatedObject<AnimationAllocPolicy> AnimationAllocatedObject; 00263 typedef AllocatedObject<SceneCtlAllocPolicy> SceneCtlAllocatedObject; 00264 typedef AllocatedObject<SceneObjAllocPolicy> SceneObjAllocatedObject; 00265 typedef AllocatedObject<ResourceAllocPolicy> ResourceAllocatedObject; 00266 typedef AllocatedObject<ScriptingAllocPolicy> ScriptingAllocatedObject; 00267 typedef AllocatedObject<RenderSysAllocPolicy> RenderSysAllocatedObject; 00268 00269 00270 // Per-class allocators defined here 00271 // NOTE: small, non-virtual classes should not subclass an allocator 00272 // the virtual function table could double their size and make them less efficient 00273 // use primitive or STL allocators / deallocators for those 00274 typedef ScriptingAllocatedObject AbstractNodeAlloc; 00275 typedef AnimationAllocatedObject AnimableAlloc; 00276 typedef AnimationAllocatedObject AnimationAlloc; 00277 typedef GeneralAllocatedObject ArchiveAlloc; 00278 typedef GeometryAllocatedObject BatchedGeometryAlloc; 00279 typedef RenderSysAllocatedObject BufferAlloc; 00280 typedef GeneralAllocatedObject CodecAlloc; 00281 typedef ResourceAllocatedObject CompositorInstAlloc; 00282 typedef GeneralAllocatedObject ConfigAlloc; 00283 typedef GeneralAllocatedObject ControllerAlloc; 00284 typedef GeometryAllocatedObject DebugGeomAlloc; 00285 typedef GeneralAllocatedObject DynLibAlloc; 00286 typedef GeometryAllocatedObject EdgeDataAlloc; 00287 typedef GeneralAllocatedObject FactoryAlloc; 00288 typedef SceneObjAllocatedObject FXAlloc; 00289 typedef GeneralAllocatedObject ImageAlloc; 00290 typedef GeometryAllocatedObject IndexDataAlloc; 00291 typedef GeneralAllocatedObject LogAlloc; 00292 typedef SceneObjAllocatedObject MovableAlloc; 00293 typedef SceneCtlAllocatedObject NodeAlloc; 00294 typedef SceneObjAllocatedObject OverlayAlloc; 00295 typedef RenderSysAllocatedObject GpuParamsAlloc; 00296 typedef ResourceAllocatedObject PassAlloc; 00297 typedef GeometryAllocatedObject PatchAlloc; 00298 typedef GeneralAllocatedObject PluginAlloc; 00299 typedef GeneralAllocatedObject ProfilerAlloc; 00300 typedef GeometryAllocatedObject ProgMeshAlloc; 00301 typedef SceneCtlAllocatedObject RenderQueueAlloc; 00302 typedef RenderSysAllocatedObject RenderSysAlloc; 00303 typedef GeneralAllocatedObject RootAlloc; 00304 typedef ResourceAllocatedObject ResourceAlloc; 00305 typedef GeneralAllocatedObject SerializerAlloc; 00306 typedef SceneCtlAllocatedObject SceneMgtAlloc; 00307 typedef ScriptingAllocatedObject ScriptCompilerAlloc; 00308 typedef ScriptingAllocatedObject ScriptTranslatorAlloc; 00309 typedef SceneCtlAllocatedObject ShadowDataAlloc; 00310 typedef GeneralAllocatedObject StreamAlloc; 00311 typedef SceneObjAllocatedObject SubEntityAlloc; 00312 typedef ResourceAllocatedObject SubMeshAlloc; 00313 typedef ResourceAllocatedObject TechniqueAlloc; 00314 typedef GeneralAllocatedObject TimerAlloc; 00315 typedef ResourceAllocatedObject TextureUnitStateAlloc; 00316 typedef GeneralAllocatedObject UtilityAlloc; 00317 typedef GeometryAllocatedObject VertexDataAlloc; 00318 typedef RenderSysAllocatedObject ViewportAlloc; 00319 typedef SceneCtlAllocatedObject LodAlloc; 00320 typedef GeneralAllocatedObject FileSystemLayerAlloc; 00321 00322 // Containers (by-value only) 00323 // Will be of the form: 00324 // typedef STLAllocator<T, DefaultAllocPolicy, Category> TAlloc; 00325 // for use in vector<T, TAlloc>::type 00326 00327 00328 00329 } 00330 00331 // Util functions 00332 namespace Ogre 00333 { 00345 template<typename T> 00346 T* constructN(T* basePtr, size_t count) 00347 { 00348 for (size_t i = 0; i < count; ++i) 00349 { 00350 new ((void*)(basePtr+i)) T(); 00351 } 00352 return basePtr; 00353 } 00357 } 00358 // define macros 00359 00367 #if OGRE_DEBUG_MODE 00368 00370 # define OGRE_MALLOC(bytes, category) ::Ogre::CategorisedAllocPolicy<category>::allocateBytes(bytes, __FILE__, __LINE__, __FUNCTION__) 00371 00372 # define OGRE_ALLOC_T(T, count, category) static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__)) 00373 00374 # define OGRE_FREE(ptr, category) ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr) 00375 00377 # define OGRE_NEW_T(T, category) new (::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T), __FILE__, __LINE__, __FUNCTION__)) T 00378 00379 # define OGRE_NEW_ARRAY_T(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__)), count) 00380 00381 # define OGRE_DELETE_T(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr);} 00382 00383 # 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);} 00384 00385 // aligned allocation 00387 # define OGRE_MALLOC_SIMD(bytes, category) ::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(bytes, __FILE__, __LINE__, __FUNCTION__) 00388 00389 # define OGRE_MALLOC_ALIGN(bytes, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(bytes, __FILE__, __LINE__, __FUNCTION__) 00390 00391 # define OGRE_ALLOC_T_SIMD(T, count, category) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__)) 00392 00393 # define OGRE_ALLOC_T_ALIGN(T, count, category, align) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T)*(count), __FILE__, __LINE__, __FUNCTION__)) 00394 00395 # define OGRE_FREE_SIMD(ptr, category) ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes(ptr) 00396 00397 # define OGRE_FREE_ALIGN(ptr, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes(ptr) 00398 00400 # define OGRE_NEW_T_SIMD(T, category) new (::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T), __FILE__, __LINE__, __FUNCTION__)) T 00401 00402 # 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) 00403 00404 # define OGRE_DELETE_T_SIMD(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes(ptr);} 00405 00406 # 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);} 00407 00408 # define OGRE_NEW_T_ALIGN(T, category, align) new (::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T), __FILE__, __LINE__, __FUNCTION__)) T 00409 00410 # 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) 00411 00412 # define OGRE_DELETE_T_ALIGN(ptr, T, category, align) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes(ptr);} 00413 00414 # 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);} 00415 00416 // new / delete for classes deriving from AllocatedObject (alignment determined by per-class policy) 00417 // Also hooks up the file/line/function params 00418 // Can only be used with classes that derive from AllocatedObject since customised new/delete needed 00419 # define OGRE_NEW new (__FILE__, __LINE__, __FUNCTION__) 00420 # define OGRE_DELETE delete 00421 00422 00423 #else // !OGRE_DEBUG_MODE 00424 00426 # define OGRE_MALLOC(bytes, category) ::Ogre::CategorisedAllocPolicy<category>::allocateBytes(bytes) 00427 00428 # define OGRE_ALLOC_T(T, count, category) static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count))) 00429 00430 # define OGRE_FREE(ptr, category) ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr) 00431 00433 # define OGRE_NEW_T(T, category) new (::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T))) T 00434 00435 # define OGRE_NEW_ARRAY_T(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAllocPolicy<category>::allocateBytes(sizeof(T)*(count))), count) 00436 00437 # define OGRE_DELETE_T(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAllocPolicy<category>::deallocateBytes((void*)ptr);} 00438 00439 # 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);} 00440 00441 // aligned allocation 00443 # define OGRE_MALLOC_SIMD(bytes, category) ::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(bytes) 00444 00445 # define OGRE_MALLOC_ALIGN(bytes, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(bytes) 00446 00447 # define OGRE_ALLOC_T_SIMD(T, count, category) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T)*(count))) 00448 00449 # define OGRE_ALLOC_T_ALIGN(T, count, category, align) static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T)*(count))) 00450 00451 # define OGRE_FREE_SIMD(ptr, category) ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes((void*)ptr) 00452 00453 # define OGRE_FREE_ALIGN(ptr, category, align) ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes((void*)ptr) 00454 00456 # define OGRE_NEW_T_SIMD(T, category) new (::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T))) T 00457 00458 # define OGRE_NEW_ARRAY_T_SIMD(T, count, category) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category>::allocateBytes(sizeof(T)*(count))), count) 00459 00460 # define OGRE_DELETE_T_SIMD(ptr, T, category) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category>::deallocateBytes((void*)ptr);} 00461 00462 # 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);} 00463 00464 # define OGRE_NEW_T_ALIGN(T, category, align) new (::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T))) T 00465 00466 # define OGRE_NEW_ARRAY_T_ALIGN(T, count, category, align) ::Ogre::constructN(static_cast<T*>(::Ogre::CategorisedAlignAllocPolicy<category, align>::allocateBytes(sizeof(T)*(count))), count) 00467 00468 # define OGRE_DELETE_T_ALIGN(ptr, T, category, align) if(ptr){(ptr)->~T(); ::Ogre::CategorisedAlignAllocPolicy<category, align>::deallocateBytes((void*)ptr);} 00469 00470 # 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);} 00471 00472 // new / delete for classes deriving from AllocatedObject (alignment determined by per-class policy) 00473 # define OGRE_NEW new 00474 # define OGRE_DELETE delete 00475 00476 #endif // OGRE_DEBUG_MODE 00477 00478 00479 namespace Ogre 00480 { 00485 template<typename T> 00486 void deletePtr(T* ptr) 00487 { 00488 OGRE_DELETE ptr; 00489 } 00490 } 00491 00496 #include "OgreHeaderSuffix.h" 00497 00498 #endif
Copyright © 2012 Torus Knot Software Ltd

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Mon Jul 27 2020 13:40:44