Utils.cpp

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2007-2008 Anael Orlinski
00003 *
00004 * This file is part of Panomatic.
00005 *
00006 * Panomatic is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * Panomatic is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with Panomatic; if not, write to the Free Software
00018 * <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 #include "Utils.h"
00022 #if defined(HW_NCPU) || defined(__APPLE__)
00023 #include <sys/sysctl.h>
00024 #endif
00025 #ifdef _WINDOWS
00026 #include <Windows.h>
00027 #include <algorithm>
00028 #elif defined __APPLE__
00029 #include <CoreServices/CoreServices.h>  //for gestalt
00030 #else
00031 #include <unistd.h>
00032 #endif
00033 
00034 #ifdef _WINDOWS
00035 unsigned long long utils::getTotalMemory()
00036 {
00037     MEMORYSTATUSEX status;
00038     status.dwLength = sizeof(status);
00039     GlobalMemoryStatusEx(&status);
00040 #ifndef _WIN64
00041     // when compiled as 32 bit version, we can only use about 2 GB
00042     // even if we have more memory available on a 64 bit system
00043     return std::min<unsigned long long>(status.ullTotalPhys, 1500*1024*1024);
00044 #else
00045     return status.ullTotalPhys;
00046 #endif
00047 };
00048 #elif defined __APPLE__
00049 unsigned long long utils::getTotalMemory()
00050 {
00051     SInt32 ramSize;
00052     if(Gestalt(gestaltPhysicalRAMSizeInMegabytes, &ramSize)==noErr)
00053     {
00054         unsigned long long _ramSize = ramSize;
00055         return _ramSize * 1024 * 1024;
00056     }
00057     else
00058     {
00059         // if query was not successful return 1 GB, 
00060         // return 0 would result in crash in calling function
00061         return 1024*1024*1024;
00062     }
00063 };
00064 #else
00065 unsigned long long utils::getTotalMemory()
00066 {
00067     long pages = sysconf(_SC_PHYS_PAGES);
00068     long page_size = sysconf(_SC_PAGE_SIZE);
00069     return pages * page_size;
00070 }
00071 #endif

Generated on 31 Jul 2015 for Hugintrunk by  doxygen 1.4.7