15 #include <mrpt/config.h> 20 #include <mach/mach_init.h> 21 #include <mach/task.h> 42 #if defined(HAVE_ALIGNED_MALLOC) 43 #if defined(__GNUC__) && !defined(__MINGW32__) 46 return _aligned_malloc(bytes, alignment);
48 #elif defined(HAVE_POSIX_MEMALIGN) 50 int ret = posix_memalign(&ptr, alignment, bytes);
55 return ::malloc(bytes);
66 void* old_ptr,
size_t bytes,
size_t alignment)
68 #if defined(HAVE_ALIGNED_MALLOC) 69 #if defined(__GNUC__) && !defined(__MINGW32__) 72 return _aligned_realloc(old_ptr, bytes, alignment);
74 #elif defined(HAVE_POSIX_MEMALIGN) 76 return ::realloc(old_ptr, bytes);
80 return ::realloc(old_ptr, bytes);
89 #if defined(HAVE_ALIGNED_MALLOC) 90 #if defined(__GNUC__) && !defined(__MINGW32__) 95 #elif defined(HAVE_POSIX_MEMALIGN) 103 #ifdef MRPT_OS_WINDOWS 106 typedef struct _PROCESS_MEMORY_COUNTERS
109 DWORD PageFaultCount;
110 SIZE_T PeakWorkingSetSize;
111 SIZE_T WorkingSetSize;
112 SIZE_T QuotaPeakPagedPoolUsage;
113 SIZE_T QuotaPagedPoolUsage;
114 SIZE_T QuotaPeakNonPagedPoolUsage;
115 SIZE_T QuotaNonPagedPoolUsage;
116 SIZE_T PagefileUsage;
117 SIZE_T PeakPagefileUsage;
118 } PROCESS_MEMORY_COUNTERS, *PPROCESS_MEMORY_COUNTERS;
129 class CAuxPSAPI_Loader
132 typedef BOOL(WINAPI* TGetProcessMemoryInfo)(
133 HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb);
135 TGetProcessMemoryInfo m_ptr;
144 m_dll = LoadLibraryA(
"PSAPI.DLL");
147 m_ptr = (TGetProcessMemoryInfo)GetProcAddress(
148 m_dll,
"GetProcessMemoryInfo");
161 BOOL WINAPI GetProcessMemoryInfo(
162 HANDLE Process, PPROCESS_MEMORY_COUNTERS ppsmemCounters, DWORD cb)
169 return (*m_ptr)(Process, ppsmemCounters, cb);
188 unsigned long MEM = 0;
190 #ifdef MRPT_OS_WINDOWS 192 static CAuxPSAPI_Loader PSAPI_LOADER;
194 PROCESS_MEMORY_COUNTERS pmc;
195 pmc.cb =
sizeof(pmc);
197 if (PSAPI_LOADER.GetProcessMemoryInfo(
198 GetCurrentProcess(), &pmc,
sizeof(pmc)))
200 MEM = (long)pmc.PagefileUsage;
208 FILE* f =
::fopen(
"/proc/self/stat",
"r");
216 "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d " 217 "%*d %*d %*d %*d %*d %*u %lu",
228 mach_task_basic_info info;
229 mach_msg_type_number_t
count = MACH_TASK_BASIC_INFO_COUNT;
231 mach_task_self(), MACH_TASK_BASIC_INFO, (task_info_t)&info,
234 MEM = info.virtual_size;
GLuint GLuint GLsizei count
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
int void fclose(FILE *f)
An OS-independent version of fclose.
#define THROW_EXCEPTION(msg)
void * aligned_realloc(void *old_ptr, size_t bytes, size_t alignment)
Frees a memory block reserved by aligned_malloc.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
unsigned long getMemoryUsage()
Returns the memory occupied by this process, in bytes.
void * aligned_malloc(size_t bytes, size_t alignment)
Returns an aligned memory block.
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
void aligned_free(void *p)
Frees a memory block reserved by aligned_malloc.