Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _MITK_MEMORY_UTILITIES_H_
00019 #define _MITK_MEMORY_UTILITIES_H_
00020
00021 #include <itkMacro.h>
00022 #include <itkExceptionObject.h>
00023 #include "mitkCommon.h"
00024
00025 namespace mitk
00026 {
00027 class MITK_CORE_EXPORT MemoryUtilities
00028 {
00029 public:
00037 static size_t GetProcessMemoryUsage();
00038
00042 static size_t GetTotalSizeOfPhysicalRam();
00043
00054 template <typename ElementType>
00055 static ElementType* AllocateElements(size_t numberOfElements, bool noThrow = false )
00056 {
00057
00058
00059
00060 ElementType* data = NULL;
00061 try
00062 {
00063 data = new ElementType[numberOfElements];
00064 }
00065 catch(...)
00066 {
00067 data = NULL;
00068 }
00069 if( ( data == NULL ) && ( noThrow == false ) )
00070 {
00071 throw itk::MemoryAllocationError(__FILE__, __LINE__, "Failed to allocate memory.", ITK_LOCATION);
00072 }
00073 return data;
00074 }
00075
00080 template <typename ElementType>
00081 static void DeleteElements(ElementType* elements)
00082 {
00083 if ( elements != NULL )
00084 {
00085 delete[] elements;
00086 }
00087 }
00088
00089 protected:
00090 #ifndef _MSC_VER
00091 static int ReadStatmFromProcFS( int* size, int* res, int* shared, int* text, int* sharedLibs, int* stack, int* dirtyPages );
00092 #endif
00093
00094 };
00095 }
00096
00097 #endif
00098
00099