Added support for osg::MemoryManager which is based upon Paul Nettle's

memory manager published at flipcode.com.  This can be turned on
with the OSG_USE_MEMORY_MANGER option which then uses custom global
new and delete operators as well as provide osgNew and osgDelete macro's
which add ability to log line and file from which calls are made.

Updated osg,osgUtil,osgDB,osgText and osgPlugins/osg to use osgNew/osgDelete,
and fixed memory leaks highlighted by the new memory manager.
This commit is contained in:
Robert Osfield
2002-03-26 23:52:52 +00:00
parent 72ff3186df
commit 84d2d01163
107 changed files with 469 additions and 435 deletions

View File

@@ -33,4 +33,6 @@
#endif
#endif
#include <osg/MemoryManager>
#endif

View File

@@ -150,9 +150,9 @@ class SG_EXPORT GeoSet : public Drawable
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
GeoSet(const GeoSet& geoset,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual Object* cloneType() const { return new GeoSet(); }
virtual Object* cloneType() const { return osgNew GeoSet(); }
virtual Object* clone(const CopyOp& copyop) const { return new GeoSet(*this,copyop); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew GeoSet(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const GeoSet*>(obj)!=NULL; }

View File

@@ -24,8 +24,8 @@ class SG_EXPORT Image : public Object
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
Image(const Image& image,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual Object* cloneType() const { return new Image(); }
virtual Object* clone(const CopyOp& copyop) const { return new Image(*this,copyop); }
virtual Object* cloneType() const { return osgNew Image(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew Image(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Image*>(obj)!=0; }
virtual const char* className() const { return "Image"; }

View File

@@ -32,11 +32,11 @@ class SG_EXPORT ImpostorSprite : public Drawable
ImpostorSprite();
/** Clone an object of the same type as an ImpostorSprite.*/
virtual Object* cloneType() const { return new ImpostorSprite(); }
virtual Object* cloneType() const { return osgNew ImpostorSprite(); }
/** Clone on ImpostorSprite just returns a clone of type,
* since it is not appropriate to share data of an ImpostorSprite.*/
virtual Object* clone(const CopyOp&) const { return new ImpostorSprite(); }
virtual Object* clone(const CopyOp&) const { return osgNew ImpostorSprite(); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ImpostorSprite*>(obj)!=NULL; }
virtual const char* className() const { return "ImpostorSprite"; }

View File

@@ -5,7 +5,6 @@
#ifndef OSG_LIGHTSOURCE
#define OSG_LIGHTSOURCE 1
#include <osg/MemoryAdapter>
#include <osg/NodeVisitor>
#include <osg/Light>

View File

@@ -40,8 +40,8 @@ class SG_EXPORT Matrix : public Object
float a20, float a21, float a22, float a23,
float a30, float a31, float a32, float a33);
virtual Object* cloneType() const { return new Matrix(); } \
virtual Object* clone(const CopyOp&) const { return new Matrix(*this); } \
virtual Object* cloneType() const { return osgNew Matrix(); } \
virtual Object* clone(const CopyOp&) const { return osgNew Matrix(*this); } \
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Matrix*>(obj)!=NULL; } \
virtual const char* className() const { return "Matrix"; }

View File

@@ -14,6 +14,9 @@
#ifndef _H_MMGR
#define _H_MMGR
#include <stdlib.h>
#include <new>
// ---------------------------------------------------------------------------------------------------------------------------------
// For systems that don't have the __FUNCTION__ variable, we can just define it here
// ---------------------------------------------------------------------------------------------------------------------------------
@@ -80,6 +83,7 @@ void m_setOwner(const char *file, const unsigned int line, const char *func);
bool &m_breakOnRealloc(void *reportedAddress);
bool &m_breakOnDealloc(void *reportedAddress);
void m_breakOnAllocation(unsigned int count);
// ---------------------------------------------------------------------------------------------------------------------------------
// The meat of the memory tracking software
@@ -119,14 +123,14 @@ sMStats m_getMemoryStatistics();
// Variations of global operators new & delete
// ---------------------------------------------------------------------------------------------------------------------------------
#ifdef OSG_USE_MEMORY_TRACKING
#ifdef OSG_USE_MEMORY_MANAGER
void *operator new(size_t reportedSize);
void *operator new[](size_t reportedSize);
void *operator new(size_t reportedSize, const char *sourceFile, int sourceLine);
void *operator new[](size_t reportedSize, const char *sourceFile, int sourceLine);
void operator delete(void *reportedAddress);
void operator delete[](void *reportedAddress);
void *operator new(size_t reportedSize) throw (std::bad_alloc);
void *operator new[](size_t reportedSize) throw (std::bad_alloc);
void *operator new(size_t reportedSize, const char *sourceFile, int sourceLine) throw (std::bad_alloc);
void *operator new[](size_t reportedSize, const char *sourceFile, int sourceLine) throw (std::bad_alloc);
void operator delete(void *reportedAddress) throw ();
void operator delete[](void *reportedAddress) throw ();
// ---------------------------------------------------------------------------------------------------------------------------------
// Macros -- "Kids, please don't try this at home. We're trained professionals here." :)

View File

@@ -23,8 +23,8 @@ class Group;
* and accept methods. Use when subclassing from Node to make it
* more convinient to define the required pure virtual methods.*/
#define META_Node(name) \
virtual osg::Object* cloneType() const { return new name (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
virtual osg::Object* cloneType() const { return osgNew name (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return osgNew name (*this,copyop); } \
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
virtual const char* className() const { return #name; } \
virtual void accept(osg::NodeVisitor& nv) { if (nv.validNodeMask(*this)) { nv.pushOntoNodePath(this); nv.apply(*this); nv.popFromNodePath(); } } \
@@ -46,10 +46,10 @@ class SG_EXPORT Node : public Object
Node(const Node&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
/** clone the an object of the same type as the node.*/
virtual Object* cloneType() const { return new Node(); }
virtual Object* cloneType() const { return osgNew Node(); }
/** return a clone of a node, with Object* return type.*/
virtual Object* clone(const CopyOp& copyop) const { return new Node(*this,copyop); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew Node(*this,copyop); }
/** return true if this and obj are of the same kind of object.*/
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Node*>(obj)!=NULL; }

View File

@@ -9,6 +9,7 @@
#include <iostream>
#include <fstream>
#include <memory>
namespace osg {
@@ -32,7 +33,7 @@ enum NotifySeverity {
SG_EXPORT extern NotifySeverity g_NotifyLevel;
/** global notify nul stream. added for Mac OSX */
SG_EXPORT extern std::ofstream *g_NotifyNulStream;
SG_EXPORT extern std::auto_ptr<std::ofstream> g_NotifyNulStream;
/** global notify nul stream. added for Mac OSX */
SG_EXPORT extern bool g_NotifyInit;

View File

@@ -15,8 +15,8 @@ namespace osg {
* the standard pure virtual clone, isSameKindAs and className methods
* which are required for all Object subclasses.*/
#define META_Object(T) \
virtual osg::Object* cloneType() const { return new T (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new T (*this,copyop); } \
virtual osg::Object* cloneType() const { return osgNew T (); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return osgNew T (*this,copyop); } \
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const T *>(obj)!=NULL; } \
virtual const char* className() const { return #T; }

View File

@@ -22,8 +22,8 @@ class StateSet;
* the standard pure virtual methods which are required for all Object
* subclasses.*/
#define META_StateAttribute(name,type) \
virtual osg::Object* cloneType() const { return new name(); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new name (*this,copyop); } \
virtual osg::Object* cloneType() const { return osgNew name(); } \
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return osgNew name (*this,copyop); } \
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const name *>(obj)!=NULL; } \
virtual const char* className() const { return #name; } \
virtual const Type getType() const { return type; }

View File

@@ -30,8 +30,8 @@ class SG_EXPORT StateSet : public Object
StateSet();
StateSet(const StateSet&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual Object* cloneType() const { return new StateSet(); }
virtual Object* clone(const CopyOp& copyop) const { return new StateSet(*this,copyop); }
virtual Object* cloneType() const { return osgNew StateSet(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew StateSet(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const StateSet*>(obj)!=NULL; }
virtual const char* className() const { return "StateSet"; }

View File

@@ -170,7 +170,7 @@ class mem_ptr
// return s_newMemoryAdapter.get();
// }
//
// T* allocate(int no) { cout<<"Allocating Memory"<<endl;return new T[no]; }
// T* allocate(int no) { cout<<"Allocating Memory"<<endl;return osgNew T[no]; }
//
// virtual void ref_data(void* userData)
// {

View File

@@ -23,4 +23,6 @@
# define OSGDB_EXPORT
#endif
#include <osg/MemoryManager>
#endif

View File

@@ -5,10 +5,10 @@
#ifndef OSG_GLUT
#define OSG_GLUT 1
#ifdef __APPLE__
#include </System/Library/Frameworks/GLUT.Framework/Versions/A/Headers/glut.h>
#if defined(__DARWIN_OSX__)
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#include <GL/glut.h>
#endif
#endif // __osgGLUT_h