From 14d33b3c1fd629ca3ebc2f369b38d9d2ebc09e2e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 18 Aug 2009 15:37:31 +0000 Subject: BGE guardedalloc, Uses WITH_CXX_GUARDEDALLOC but gives a string to MEM_mallocN for better tracking memory usage. * off by default. * new/delete are at the bottom of each class * python BGE objects have the new/delete in the Py_Header macro. --- source/gameengine/Expressions/PyObjectPlus.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source/gameengine/Expressions/PyObjectPlus.h') diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h index d68aa9f0410..e9e81dddaaa 100644 --- a/source/gameengine/Expressions/PyObjectPlus.h +++ b/source/gameengine/Expressions/PyObjectPlus.h @@ -102,7 +102,7 @@ typedef struct { // This must be the first line of each // PyC++ class -#define Py_Header \ +#define __Py_Header \ public: \ static PyTypeObject Type; \ static PyMethodDef Methods[]; \ @@ -111,6 +111,16 @@ typedef struct { virtual PyObject *GetProxy() {return GetProxy_Ext(this, &Type);}; \ virtual PyObject *NewProxy(bool py_owns) {return NewProxy_Ext(this, &Type, py_owns);}; \ + +#ifdef WITH_CXX_GUARDEDALLOC +#define Py_Header __Py_Header \ + void *operator new( unsigned int num_bytes) { return MEM_mallocN(num_bytes, Type.tp_name); } \ + void operator delete( void *mem ) { MEM_freeN(mem); } \ + +#else +#define Py_Header __Py_Header +#endif + /* * nonzero values are an error for setattr * however because of the nested lookups we need to know if the errors -- cgit v1.2.3