Ogre - Memory , Introduction
来源:互联网 发布:微pe 知乎 编辑:程序博客网 时间:2024/06/05 23:52
1. OgreConfig中的关于内存的定义
Ogre使用的默认内存分配策略是 OGRE_MEMORY_ALLOCATOR_NEDPOOLING
// define the memory allocator configuration to use
#defineOGRE_MEMORY_ALLOCATOR_STD1
#defineOGRE_MEMORY_ALLOCATOR_NED2
#defineOGRE_MEMORY_ALLOCATOR_USER3
#defineOGRE_MEMORY_ALLOCATOR_NEDPOOLING4
#ifndefOGRE_MEMORY_ALLOCATOR
# define OGRE_MEMORY_ALLOCATOR OGRE_MEMORY_ALLOCATOR_NEDPOOLING
#endif
2.
mRoot = new Ogre::Root(mPluginsCfg);
Ogre::WxMaterialBinManager* mat = OGRE_NEW Ogre::WxMaterialBinManager;
setupResources();
ResourceAlloc中重载了new操作运算符
在Debug模式下 OGRE_NEW被定义为
# define OGRE_NEWnew(__FILE__,__LINE__,__FUNCTION__)
会调用AllocatedObject的函数void* operator new(size_t sz, const char* file, intline, const char*func),
而Debug下的new仍然调用 void* operator new(size_t sz)
template<class Alloc>
class_OgreExport AllocatedObject
{
public:
explicitAllocatedObject()
{ }
~AllocatedObject()
{ }
/// operator new, with debug line info
void* operator new(size_t sz,const char*file,intline,const char* func)
{
return Alloc::allocateBytes(sz,file,line,func);
}
void* operator new(size_t sz)
{
returnAlloc::allocateBytes(sz);
}
…………
}
一个继承自ResourceAlloc的类 class /*_OgreExport*/ WxMaterialBinManager : public ScriptLoader, public ResourceAlloc { public: WxMaterialBinManager(); ~WxMaterialBinManager(); virtual const StringVector& getScriptPatterns(void) const { return mScriptPatterns; } virtual void parseScript(DataStreamPtr& stream, const String& groupName); virtual Real getLoadingOrder(void) const { return mLoadOrder; } StringVector mScriptPatterns; Real mLoadOrder; };
下面是ResourceAlloc的定义:
typedef ResourceAllocatedObject ResourceAlloc;
typedef AllocatedObject ResourceAllocatedObject;
typedef CategorisedAllocPolicy<Ogre::MEMCATEGORY_RESOURCE>ResourceAllocPolicy;
Ogre::MEMCATEGORY_RESOURCE是个内存的类型namespace Ogre{ /** /addtogroup Core * @{ */ /** /addtogroup Memory * @{ */ /** A set of categories that indicate the purpose of a chunk of memory being allocated. These categories will be provided at allocation time in order to allow the allocation policy to vary its behaviour if it wishes. This allows you to use a single policy but still have variant behaviour. The level of control it gives you is at a higher level than assigning different policies to different classes, but is the only control you have over general allocations that are primitive types. */ enum MemoryCategory { /// General purpose MEMCATEGORY_GENERAL = 0, /// Geometry held in main memory MEMCATEGORY_GEOMETRY = 1, /// Animation data like tracks, bone matrices MEMCATEGORY_ANIMATION = 2, /// Nodes, control data MEMCATEGORY_SCENE_CONTROL = 3, /// Scene object instances MEMCATEGORY_SCENE_OBJECTS = 4, /// Other resources MEMCATEGORY_RESOURCE = 5, /// Scripting MEMCATEGORY_SCRIPTING = 6, /// Rendersystem structures MEMCATEGORY_RENDERSYS = 7, // sentinel value, do not use MEMCATEGORY_COUNT = 8 }; /** @} */ /** @} */}
使用的内存分配策略
#if OGRE_MEMORY_ALLOCATOR==OGRE_MEMORY_ALLOCATOR_NEDPOOLING
# include"OgreMemoryNedPooling.h"
namespace Ogre
{
// configure default allocators based on the options above
// notice how we're not using the memory categories here but still roughing them out
// in your allocators you might choose to create different policies per category
// configurable category, for general malloc
// notice how we ignore the category here, you could specialise
template<MemoryCategory Cat>classCategorisedAllocPolicy:publicNedPoolingPolicy{};
template<MemoryCategory Cat,size_t align= 0>classCategorisedAlignAllocPolicy:publicNedPoolingAlignedPolicy<align>{};
}
#elif OGRE_MEMORY_ALLOCATOR==OGRE_MEMORY_ALLOCATOR_NED
……其它策略
3.CategorisedAllocPolicy 继承自 NedPoolingPolicy;
/** An allocation policy for use with AllocatedObject and STLAllocator. This is the class that actually does the allocationand deallocation of physical memory, and is what you will want to provide a custom version of if you wish to change how memory is allocated.@parThis allocation policy uses nedmalloc (http://nedprod.com/programs/portable/nedmalloc/index.html). */class _OgreExport NedPoolingPolicy{public: static inline void* allocateBytes(size_t count, const char* file = 0, int line = 0, const char* func = 0) { return NedPoolingImpl::allocBytes(count, file, line, func); } static inline void deallocateBytes(void* ptr) { NedPoolingImpl::deallocBytes(ptr); } /// Get the maximum size of a single allocation static inline size_t getMaxAllocationSize() { return std::numeric_limits<size_t>::max(); }private: // No instantiation NedPoolingPolicy() { }};
- Ogre - Memory , Introduction
- Memory allocate in Ogre
- The Introduction of Memory Leaks
- The Introduction of Memory Leaks
- The Introduction of Memory Leaks
- OGRE - Memory , nedmalloc结构分析
- Memory access ordering Part 1 - an introduction
- Flash memory 101: An Introduction to NAND flash
- 内存磁盘介绍 introduction of memory disk software
- Introduction to C Memory Management and C++ Object-Oriented Programming
- The Android ION memory allocator - Only an Introduction
- Coursera_An Introduction to Interactive Programming in Python_Mini-project # 5 Memory
- Introduction
- Introduction
- Introduction
- Introduction
- Introduction
- Introduction
- vc++ resource.h文件出现“fatal error RC1004: unexpected end of file found”问题 .
- android中 sqlite数据库插入速度的优化
- Eclipse快捷键指南
- VC用ADO连接oracle的方法 .
- 两个古老问题的递归算法。
- Ogre - Memory , Introduction
- 我php函数 2 字符串
- Jxls导出excel的若干方式总结(八)-- 导出一条查询记录到多个sheet
- Windows批处理命令
- OGRE - MultiThread
- Android中的内存管理
- VisionMobile: 开放管控指数(四) -- 开源管控:Eclipse
- android string.xml中的string转义
- 我的php函数 3 数组