MObject.cpp
Go to the documentation of this file.
00001 #include "MObject.h"
00002 #include "GlobalResource.h"
00003 #include <cstdlib>
00004 #include <sstream>
00005 #include <new>
00006 
00007 using namespace std;
00008 using namespace momdp;
00009 namespace momdp 
00010 {
00011         MObject::MObject(void) : referenceCount(0)
00012         {
00013                 
00014         }
00015 
00016         MObject::~MObject(void)
00017         {
00018         }
00019         void *MObject::operator new(size_t nSize)
00020         {
00021                 void *p;
00022 
00023                 //cout << "new devector.\n";
00024 
00025                 p =  malloc(nSize);
00026                 //p = (void *) new char [nSize];
00027 
00028                 GlobalResource::getInstance()->memoryUsage += nSize;
00029                 GlobalResource::getInstance()->checkMemoryUsage();
00030 
00031                 if(!p) 
00032                 {
00033                         bad_alloc ba;
00034                         throw ba;
00035                         //throw new bad_alloc();
00036                 }
00037                 MObject *objP = (MObject *)p;
00038 
00039                 objP->thisSize = nSize;
00040 
00041                 return p;
00042         }
00043 
00044         // delete operator overloaded
00045         void MObject::operator delete(void *p)
00046         {
00047                 MObject *objP = (MObject *)p;
00048                 //cout << "delete DenseVector.\n";
00049                 GlobalResource::getInstance()->memoryUsage -= objP->thisSize;
00050                 free(p);
00051                 //delete [] p;
00052         }
00053 
00054         // ToString
00055         string MObject::ToString()
00056         {
00057                 stringstream sb;
00058                 sb << "Object at " << this;
00059 
00060                 return sb.str();
00061         }
00062 
00063 }


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29