memory.h

Go to the documentation of this file.
00001 /*
00002  * This program is free software; you can redistribute it and/or modify
00003  * it under the terms of the GNU General Public License as published by
00004  * the Free Software Foundation; either version 3 of the License, or
00005  * (at your option) any later version.
00006  *
00007  * Written (W) 2008-2009 Soeren Sonnenburg
00008  * Copyright (C) 2008-2009 Fraunhofer Institute FIRST and Max-Planck-Society
00009  */
00010 
00011 #ifndef __MEMORY_H__
00012 #define __MEMORY_H__
00013 
00014 #include <stdio.h>
00015 #include <stdlib.h>
00016 
00017 #include <new>
00018 
00019 void* operator new(size_t size) throw (std::bad_alloc);
00020 void operator delete(void *p);
00021 
00022 void* operator new[](size_t size);
00023 void operator delete[](void *p);
00024 
00025 
00026 #ifdef TRACE_MEMORY_ALLOCS
00027 namespace shogun
00028 {
00029 class MemoryBlock
00030 {
00031     public:
00032         MemoryBlock(void* p)
00033         {
00034             ptr=p;
00035             size=0;
00036         }
00037 
00038         MemoryBlock(void* p, size_t sz)
00039         {
00040             ptr=p;
00041             size=sz;
00042         }
00043 
00044         MemoryBlock(const MemoryBlock &b)
00045         {
00046             ptr=b.ptr;
00047             size=b.size;
00048         }
00049 
00050 
00051         bool operator==(const MemoryBlock &b) const
00052         {
00053             return ptr==b.ptr;
00054         }
00055 
00056         void display()
00057         {
00058             printf("Object at %p of size %lld bytes\n", ptr, (long long int) size);
00059         }
00060 
00061     protected:
00062         void* ptr;
00063         size_t size;
00064 };
00065 
00066 void list_memory_allocs();
00067 }
00068 #endif
00069 #endif // __MEMORY_H__
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation