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 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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 #elif defined __APPLE__
00028 #include <CoreServices/CoreServices.h>  //for gestalt
00029 #else
00030 #include <unistd.h>
00031 #endif
00032 
00033 #ifdef _WINDOWS
00034 unsigned long long utils::getTotalMemory()
00035 {
00036     MEMORYSTATUSEX status;
00037     status.dwLength = sizeof(status);
00038     GlobalMemoryStatusEx(&status);
00039 #ifndef _WIN64
00040     // when compiled as 32 bit version, we can only use about 2 GB
00041     // even if we have more memory available on a 64 bit system
00042     return std::min<unsigned long long>(status.ullTotalPhys, 1500*1024*1024);
00043 #else
00044     return status.ullTotalPhys;
00045 #endif
00046 };
00047 #elif defined __APPLE__
00048 unsigned long long utils::getTotalMemory()
00049 {
00050     SInt32 ramSize;
00051     if(Gestalt(gestaltPhysicalRAMSizeInMegabytes, &ramSize)==noErr)
00052     {
00053         unsigned long long _ramSize = ramSize;
00054         return _ramSize * 1024 * 1024;
00055     }
00056     else
00057     {
00058         // if query was not successful return 1 GB, 
00059         // return 0 would result in crash in calling function
00060         return 1024*1024*1024;
00061     }
00062 };
00063 #else
00064 unsigned long long utils::getTotalMemory()
00065 {
00066     long pages = sysconf(_SC_PHYS_PAGES);
00067     long page_size = sysconf(_SC_PAGE_SIZE);
00068     return pages * page_size;
00069 }
00070 #endif

Generated on Wed Jul 16 01:25:39 2014 for Hugintrunk by  doxygen 1.3.9.1